Serialization Framework performance Comparison (Kryo, Hessian, Java, Protostuff)
Brief introduction:
|
Advantages |
Disadvantages |
Kryo |
Fast, small volume after serialization |
More complex cross-language support |
Hessian |
The default supports cross-language |
More slowly |
Protostuff |
Fast, based on PROTOBUF |
Static compilation required |
Protostuff-runtime |
No static compilation required, but prior to serialization, the schema must be passed in |
Classes without a default constructor are not supported, and deserialization requires the user to initialize the serialized object themselves, which is only responsible for assigning the object to the value |
Java |
Easy to use, serialization of all classes |
Slow, Occupy space |
|
|
|
|
|
|
|
|
|
Test environment:
Hardware information:
Intel (R) Xeon (r) CPU E5620 @2.40ghz
Red Hat Enterprise Linux Server Release 5.4 (Tikanga)
Java: "1.6.0_27" Java HotSpot (TM) 64-bit Server VM (build 20.2-b06, Mixed mode)
JVM Options:java-xmx256m–server
Test data: (see annex)
Arraylist.class
Mediacontent.class
Media.class
Image.class
Test method: (refer to from Https://github.com/eishay/jvm-serializers)
<!--[if!supportlists]-->1, <!--[endif]--> before the formal test, run the test case 10 times to warm up the JVM.
<!--[if!supportlists]-->2, <!--[endif]--> for each method of the test case, run 2000 times, averaging.
<!--[if!supportlists]-->3, <!--[endif]--> run 500 times per test case for optimal results
Test benchmark:
Ser: The time to create an object and serialize it into a byte array
Deser: The time to deserialize a byte array into an object
Total: Creates an object, serializes it into a byte array, and deserializes it into an object.
Size: Array sizes after serialization
SIZE+DFL: Compressed size after serialization with LEVEL6 level zlib
Test tools:
Serialization Tools |
Serialization mode |
Kryo |
Using the Kryo default serialization mode Fieldserializer, Take the default action on the object that needs to be serialized. Open reference, close register |
Protostuff |
Serialization with schema generated by static compilation |
Protostuff-runtime |
Using the Protostuff-runtime framework to generate schema for serialization |
|
|
Test results:
Time:
Size:
Summarize:
Kryo in the case of class registration and reference shutdown, serialization speed and size are significantly better than Hessian and Java, close to Protostuff. When reference is turned on, the serialization speed will be significantly slower, but still better than Hessian.
Related knowledge:
Class Registration: Registering a class that requires serialization into Kryo can increase the speed of serialization and deserialization.
Reference: When this option is turned on, the same object will be serialized to the same byte[], closed by default, if you want to support circular references, you must turn on
Stability Test:
Test cases (see annex)
Circular reference: Cyclic.java
Serialization mode |
No default constructor |
Circular references |
object is null |
Whether you need to know beforehand what class the object belongs to |
Large Object (4M) |
Kryo |
Support |
You need to open the reference option |
Support |
No, close the register. |
Support |
Java |
Support |
Support |
Support |
Don't need |
Support |
Protostuff |
Support |
Support |
Support |
Don't need |
Support |
Protostuff -runtime |
Not supported |
Support |
Support |
Need |
Support |
Hessian |
Support |
Support |
Support |
Don't need |
Support |
Via http://x-rip.iteye.com/blog/1555293
[Java] Serialization Framework performance comparison (Kryo, Hessian, Java, Protostuff)