diff --git a/protocol/pom.xml b/protocol/pom.xml
index 2134534a..36816536 100644
--- a/protocol/pom.xml
+++ b/protocol/pom.xml
@@ -136,6 +136,19 @@
test
+
+ org.furyio
+ fury-core
+ 0.1.0
+ test
+
+
+ slf4j-api
+ org.slf4j
+
+
+
+
org.springframework.boot
spring-boot-starter-logging
diff --git a/protocol/src/test/java/com/zfoo/protocol/SpeedTest.java b/protocol/src/test/java/com/zfoo/protocol/SpeedTest.java
index 77b3503b..e820ec97 100644
--- a/protocol/src/test/java/com/zfoo/protocol/SpeedTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/SpeedTest.java
@@ -24,6 +24,11 @@ import com.zfoo.protocol.collection.ArrayUtils;
import com.zfoo.protocol.generate.GenerateOperation;
import com.zfoo.protocol.packet.*;
import com.zfoo.protocol.util.StringUtils;
+import io.fury.Fury;
+import io.fury.Language;
+import io.fury.ThreadLocalFury;
+import io.fury.ThreadSafeFury;
+import io.fury.memory.MemoryBuffer;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.UnpooledHeapByteBuf;
@@ -64,6 +69,7 @@ public class SpeedTest {
System.out.println(StringUtils.format("[单线程性能测试-->[benchmark:{}]]", benchmark));
zfooTest();
+ furyTest();
protobufTest();
kryoTest();
@@ -86,6 +92,7 @@ public class SpeedTest {
System.out.println(StringUtils.format("[多线程性能测试-->[benchmark:{}]]", benchmark));
zfooMultipleThreadTest();
+ furyMultipleThreadTest();
protobufMultipleThreadTest();
kryoMultipleThreadTest();
@@ -138,6 +145,43 @@ public class SpeedTest {
System.out.println(StringUtils.format("[zfoo] [复杂对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), buffer.writerIndex(), System.currentTimeMillis() - startTime));
}
+ @Ignore
+ @Test
+ public void furyTest() {
+ var buffer = MemoryBuffer.newHeapBuffer(1_0000);
+ // 序列化和反序列化简单对象
+ long startTime = System.currentTimeMillis();
+ for (int i = 0; i < benchmark; i++) {
+ buffer.writerIndex(0);
+ buffer.readerIndex(0);
+ fury.serialize(buffer, simpleObject);
+ var obj = fury.deserialize(buffer);
+ }
+
+ System.out.println(StringUtils.format("[fury] [简单对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), buffer.writerIndex(), System.currentTimeMillis() - startTime));
+
+ // 序列化和反序列化常规对象
+ startTime = System.currentTimeMillis();
+ for (int i = 0; i < benchmark; i++) {
+ buffer.writerIndex(0);
+ buffer.readerIndex(0);
+ fury.serialize(buffer, normalObject);
+ var obj = fury.deserialize(buffer);
+ }
+
+ System.out.println(StringUtils.format("[fury] [常规对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), buffer.writerIndex(), System.currentTimeMillis() - startTime));
+
+ // 序列化和反序列化复杂对象
+ startTime = System.currentTimeMillis();
+ for (int i = 0; i < benchmark; i++) {
+ buffer.writerIndex(0);
+ buffer.readerIndex(0);
+ fury.serialize(buffer, complexObject);
+ var obj = fury.deserialize(buffer);
+ }
+ System.out.println(StringUtils.format("[fury] [复杂对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), buffer.writerIndex(), System.currentTimeMillis() - startTime));
+ }
+
@Ignore
@Test
public void kryoTest() {
@@ -241,6 +285,19 @@ public class SpeedTest {
countdown.await();
}
+ @Ignore
+ @Test
+ public void furyMultipleThreadTest() throws InterruptedException {
+ var countdown = new CountDownLatch(threadNum);
+ for (var i = 0; i < threadNum; i++) {
+ executors[i].execute(() -> {
+ furyTest();
+ countdown.countDown();
+ });
+ }
+ countdown.await();
+ }
+
@Ignore
@Test
public void kryoMultipleThreadTest() throws InterruptedException {
@@ -267,7 +324,7 @@ public class SpeedTest {
countdown.await();
}
- public static final int threadNum = Runtime.getRuntime().availableProcessors() - 1;
+ public static final int threadNum = Runtime.getRuntime().availableProcessors() / 2;
public static final ExecutorService[] executors = new ExecutorService[threadNum];
// kryo协议注册
@@ -331,6 +388,22 @@ public class SpeedTest {
}
}
+ private static ThreadSafeFury fury;
+
+ static {
+ fury = new ThreadLocalFury(classLoader -> {
+ Fury f = Fury.builder().withLanguage(Language.JAVA)
+ .build();
+ f.register(ComplexObject.class);
+ f.register(NormalObject.class);
+ f.register(SimpleObject.class);
+ f.register(VeryBigObject.class);
+ f.register(ObjectA.class);
+ f.register(ObjectB.class);
+ return f;
+ });
+ }
+
// -------------------------------------------以下为测试用例---------------------------------------------------------------
// 简单类型
public static final byte byteValue = 99;