mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-29 16:25:38 +00:00
ref[lpmap]: move lpmap from orm to protocol
This commit is contained in:
+1
-1
@@ -10,7 +10,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.orm.lpmap;
|
||||
package com.zfoo.protocol.collection.lpmap;
|
||||
|
||||
import com.zfoo.protocol.IPacket;
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.orm.lpmap;
|
||||
package com.zfoo.protocol.collection.lpmap;
|
||||
|
||||
import com.zfoo.protocol.IPacket;
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.orm.lpmap;
|
||||
package com.zfoo.protocol.collection.lpmap;
|
||||
|
||||
import com.zfoo.protocol.IPacket;
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.orm.lpmap;
|
||||
package com.zfoo.protocol.collection.lpmap;
|
||||
|
||||
import com.zfoo.protocol.IPacket;
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.orm.lpmap;
|
||||
package com.zfoo.protocol.collection.lpmap;
|
||||
|
||||
import com.zfoo.protocol.IPacket;
|
||||
import com.zfoo.protocol.ProtocolManager;
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.orm.lpmap;
|
||||
package com.zfoo.protocol.collection.lpmap;
|
||||
|
||||
import com.zfoo.protocol.IPacket;
|
||||
import com.zfoo.protocol.ProtocolManager;
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.orm.lpmap;
|
||||
package com.zfoo.protocol.collection.lpmap;
|
||||
|
||||
import com.zfoo.protocol.IPacket;
|
||||
import io.netty.util.collection.LongObjectHashMap;
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.orm.lpmap;
|
||||
package com.zfoo.protocol.collection.lpmap;
|
||||
|
||||
import com.zfoo.protocol.IPacket;
|
||||
import com.zfoo.protocol.exception.RunException;
|
||||
@@ -26,13 +26,14 @@ import java.util.concurrent.CountDownLatch;
|
||||
@Ignore
|
||||
public class ConcurrentTest {
|
||||
|
||||
private static final int EXECUTOR_SIZE = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
@Test
|
||||
public void test() throws InterruptedException {
|
||||
var map = new CopyOnWriteHashMapLongObject<Integer>();
|
||||
var num = 1_0000;
|
||||
var executorSize = Runtime.getRuntime().availableProcessors();
|
||||
var countDownLatch = new CountDownLatch(executorSize);
|
||||
for (var i = 0; i < executorSize; i++) {
|
||||
var countDownLatch = new CountDownLatch(EXECUTOR_SIZE);
|
||||
for (var i = 0; i < EXECUTOR_SIZE; i++) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -46,8 +47,8 @@ public class ConcurrentTest {
|
||||
countDownLatch.await();
|
||||
Assert.assertEquals(map.size(), num);
|
||||
|
||||
var countDownLatch2 = new CountDownLatch(executorSize);
|
||||
for (var i = 0; i < executorSize; i++) {
|
||||
var countDownLatch2 = new CountDownLatch(EXECUTOR_SIZE);
|
||||
for (var i = 0; i < EXECUTOR_SIZE; i++) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
+8
-7
@@ -10,11 +10,10 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.orm.lpmap;
|
||||
package com.zfoo.protocol.collection.lpmap;
|
||||
|
||||
import com.zfoo.event.manager.EventBus;
|
||||
import com.zfoo.orm.lpmap.model.MyPacket;
|
||||
import com.zfoo.protocol.ProtocolManager;
|
||||
import com.zfoo.protocol.collection.lpmap.model.MyPacket;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@@ -31,6 +30,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
@Ignore
|
||||
public class ConcurrentFileChannelMapTest {
|
||||
|
||||
private static final int EXECUTOR_SIZE = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
@Test
|
||||
public void benchmarkTest() throws IOException, InterruptedException {
|
||||
ProtocolManager.initProtocol(Set.of(MyPacket.class));
|
||||
@@ -39,9 +40,9 @@ public class ConcurrentFileChannelMapTest {
|
||||
var atomicInt = new AtomicInteger(0);
|
||||
var count = 1000_0000;
|
||||
|
||||
var countdown = new CountDownLatch(EventBus.EXECUTORS_SIZE);
|
||||
for (int i = 0; i < EventBus.EXECUTORS_SIZE; i++) {
|
||||
EventBus.asyncExecute(new Runnable() {
|
||||
var countdown = new CountDownLatch(EXECUTOR_SIZE);
|
||||
for (int i = 0; i < EXECUTOR_SIZE; i++) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
var key = atomicInt.getAndIncrement();
|
||||
@@ -52,7 +53,7 @@ public class ConcurrentFileChannelMapTest {
|
||||
}
|
||||
countdown.countDown();
|
||||
}
|
||||
});
|
||||
}).start();
|
||||
}
|
||||
countdown.await();
|
||||
for (var i = 0; i < count; i++) {
|
||||
+17
-13
@@ -10,10 +10,9 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.orm.lpmap;
|
||||
package com.zfoo.protocol.collection.lpmap;
|
||||
|
||||
import com.zfoo.event.manager.EventBus;
|
||||
import com.zfoo.orm.lpmap.model.MyPacket;
|
||||
import com.zfoo.protocol.collection.lpmap.model.MyPacket;
|
||||
import com.zfoo.protocol.ProtocolManager;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
@@ -31,6 +30,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
@Ignore
|
||||
public class ConcurrentHeapMapTest {
|
||||
|
||||
private static final int EXECUTOR_SIZE = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
@Test
|
||||
public void putIfAbsentTest() {
|
||||
ProtocolManager.initProtocol(Set.of(MyPacket.class));
|
||||
@@ -56,17 +57,20 @@ public class ConcurrentHeapMapTest {
|
||||
var atomicInt = new AtomicInteger(0);
|
||||
var count = 1000_0000;
|
||||
|
||||
var countdown = new CountDownLatch(EventBus.EXECUTORS_SIZE);
|
||||
for (int i = 0; i < EventBus.EXECUTORS_SIZE; i++) {
|
||||
EventBus.asyncExecute(() -> {
|
||||
var key = atomicInt.getAndIncrement();
|
||||
while (key < count) {
|
||||
var myPacket = MyPacket.valueOf(key, String.valueOf(key));
|
||||
map.put(key, myPacket);
|
||||
key = atomicInt.getAndIncrement();
|
||||
var countdown = new CountDownLatch(EXECUTOR_SIZE);
|
||||
for (int i = 0; i < EXECUTOR_SIZE; i++) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
var key = atomicInt.getAndIncrement();
|
||||
while (key < count) {
|
||||
var myPacket = MyPacket.valueOf(key, String.valueOf(key));
|
||||
map.put(key, myPacket);
|
||||
key = atomicInt.getAndIncrement();
|
||||
}
|
||||
countdown.countDown();
|
||||
}
|
||||
countdown.countDown();
|
||||
});
|
||||
}).start();
|
||||
}
|
||||
countdown.await();
|
||||
for (var i = 0; i < count; i++) {
|
||||
+2
-2
@@ -10,9 +10,9 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.orm.lpmap;
|
||||
package com.zfoo.protocol.collection.lpmap;
|
||||
|
||||
import com.zfoo.orm.lpmap.model.MyPacket;
|
||||
import com.zfoo.protocol.collection.lpmap.model.MyPacket;
|
||||
import com.zfoo.protocol.ProtocolManager;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
+2
-2
@@ -10,9 +10,9 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.orm.lpmap;
|
||||
package com.zfoo.protocol.collection.lpmap;
|
||||
|
||||
import com.zfoo.orm.lpmap.model.MyPacket;
|
||||
import com.zfoo.protocol.collection.lpmap.model.MyPacket;
|
||||
import com.zfoo.protocol.ProtocolManager;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
+2
-2
@@ -10,9 +10,9 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.orm.lpmap;
|
||||
package com.zfoo.protocol.collection.lpmap;
|
||||
|
||||
import com.zfoo.orm.lpmap.model.MyPacket;
|
||||
import com.zfoo.protocol.collection.lpmap.model.MyPacket;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zfoo.orm.lpmap.model;
|
||||
package com.zfoo.protocol.collection.lpmap.model;
|
||||
|
||||
import com.zfoo.protocol.IPacket;
|
||||
|
||||
Reference in New Issue
Block a user