diff --git a/benchmark/toy-rpc-client/src/main/java/com/sinjinsong/benchmark/toy/client/BenchmarkToyClient.java b/benchmark/toy-rpc-client/src/main/java/com/sinjinsong/benchmark/toy/client/BenchmarkToyClient.java index 2b5a0d0..09ec305 100644 --- a/benchmark/toy-rpc-client/src/main/java/com/sinjinsong/benchmark/toy/client/BenchmarkToyClient.java +++ b/benchmark/toy-rpc-client/src/main/java/com/sinjinsong/benchmark/toy/client/BenchmarkToyClient.java @@ -24,11 +24,11 @@ public static void main(String[] args) throws InterruptedException { @Override public void run(String... strings) throws Exception { - int threads = Integer.parseInt(strings[0]); - int requestTotal = Integer.parseInt(strings[1]); - int measurementIterations = Integer.parseInt(strings[2]); - client.run(threads, requestTotal,measurementIterations); -// client.run(1,1,1); +// int threads = Integer.parseInt(strings[0]); +// int requestTotal = Integer.parseInt(strings[1]); +// int measurementIterations = Integer.parseInt(strings[2]); +// client.run(threads, requestTotal,measurementIterations); + client.run(1,1,1); System.exit(0); } } \ No newline at end of file diff --git a/benchmark/toy-rpc-client/src/main/resources/application.properties b/benchmark/toy-rpc-client/src/main/resources/application.properties index 3bdcb4e..285e658 100644 --- a/benchmark/toy-rpc-client/src/main/resources/application.properties +++ b/benchmark/toy-rpc-client/src/main/resources/application.properties @@ -1,10 +1,10 @@ rpc.application.name=benchmark_consumer -rpc.application.serialize=protostuff +rpc.application.serialize=json rpc.application.proxy=javassist rpc.protocol.type=toy rpc.protocol.executor.server.type=threadpool rpc.protocol.executor.client.type=threadpool -#rpc.registry.address=127.0.0.1:2181 -rpc.registry.address=192.168.1.117:2181 +rpc.registry.address=127.0.0.1:2181 +#rpc.registry.address=192.168.1.117:2181 rpc.cluster.loadbalance=consistent_hash rpc.cluster.faulttolerance=failover diff --git a/benchmark/toy-rpc-server/src/main/resources/application.properties b/benchmark/toy-rpc-server/src/main/resources/application.properties index 5bfd44d..8b3c301 100644 --- a/benchmark/toy-rpc-server/src/main/resources/application.properties +++ b/benchmark/toy-rpc-server/src/main/resources/application.properties @@ -1,5 +1,5 @@ rpc.application.name=benchmark_provider -rpc.application.serialize=protostuff +rpc.application.serialize=json rpc.application.proxy=javassist rpc.protocol.type=toy rpc.protocol.port=8000 diff --git a/toy-rpc-core/pom.xml b/toy-rpc-core/pom.xml index 5f4ff59..1254a21 100644 --- a/toy-rpc-core/pom.xml +++ b/toy-rpc-core/pom.xml @@ -122,5 +122,11 @@ hessian 4.0.38 + + + com.alibaba + fastjson + 1.2.49 + \ No newline at end of file diff --git a/toy-rpc-core/src/main/java/com/sinjinsong/toy/common/enumeration/SerializerType.java b/toy-rpc-core/src/main/java/com/sinjinsong/toy/common/enumeration/SerializerType.java index 9d65608..c12725a 100644 --- a/toy-rpc-core/src/main/java/com/sinjinsong/toy/common/enumeration/SerializerType.java +++ b/toy-rpc-core/src/main/java/com/sinjinsong/toy/common/enumeration/SerializerType.java @@ -4,6 +4,7 @@ import com.sinjinsong.toy.serialize.api.Serializer; import com.sinjinsong.toy.serialize.hessian.HessianSerializer; import com.sinjinsong.toy.serialize.jdk.JdkSerializer; +import com.sinjinsong.toy.serialize.json.JsonSerializer; import com.sinjinsong.toy.serialize.protostuff.ProtostuffSerializer; /** @@ -13,7 +14,8 @@ public enum SerializerType implements ExtensionBaseType { PROTOSTUFF(new ProtostuffSerializer()), JDK(new JdkSerializer()), - HESSIAN(new HessianSerializer()); + HESSIAN(new HessianSerializer()), + JSON(new JsonSerializer()); private Serializer serializer; diff --git a/toy-rpc-core/src/main/java/com/sinjinsong/toy/serialize/json/JsonSerializer.java b/toy-rpc-core/src/main/java/com/sinjinsong/toy/serialize/json/JsonSerializer.java new file mode 100644 index 0000000..2a55460 --- /dev/null +++ b/toy-rpc-core/src/main/java/com/sinjinsong/toy/serialize/json/JsonSerializer.java @@ -0,0 +1,21 @@ +package com.sinjinsong.toy.serialize.json; + +import com.alibaba.fastjson.JSONObject; +import com.sinjinsong.toy.common.exception.RPCException; +import com.sinjinsong.toy.serialize.api.Serializer; + +/** + * @author sinjinsong + * @date 2018/8/23 + */ +public class JsonSerializer implements Serializer { + @Override + public byte[] serialize(T obj) throws RPCException { + return JSONObject.toJSONBytes(obj); + } + + @Override + public T deserialize(byte[] data, Class cls) throws RPCException { + return JSONObject.parseObject(data, cls); + } +}