Discussion on object serialization

Source: Internet
Author: User

What is serialization is an operation that encodes the instantaneous state of an instance of a class in a particular way, called object serialization. is to turn the various properties of the object at this moment into a binary stream according to certain rules, and then, if transferred to another JVM, the JVM can deserialize the binary stream into its corresponding object, and the object has the data and various attributes at that time. The main function of serialization is to transfer the serialized object to network, which can realize the functions of object invocation, distributed object and so on. Serialized indicator 1, object serialized size an object is serialized by the serialization tool into a string of byte arrays, which contains the field value of the object and the metadata information so that it can be deserialized back to an object 2, The speed of serialization and deserialization an object is serialized into a byte array at a time depending on how it generates/parses a byte array Method 3, the serialization tool itself, the speed of the serialization tool itself is created with a certain amount of consumption. Various serialization comparisons to the Java Serialization principle: classes need to implement the serializable interface to be serialized by the JDK's own serialization mechanism, and when the JDK is serialized, the class and all of his superclass metadata, class descriptions, attributes, property values, and so on, are serialized out. This causes the size of the serialization to be larger and slower, but contains the most comprehensive content. can be completely deserialized.

Kryo serialization principle: When serializing, the information of the object, the object property value information, and so on, and does not serialize the descriptive information of the class field, which is much smaller than the JDK's own serialization, and the speed is certainly faster, but the information contains no JDK comprehensive. Similar

Hessian serialization principle: when serializing, but also the information of the object, attribute value information and so on serialization, will be more than the JDK itself after the serialization of a lot smaller, but no kryo small, very fast, similar.

  The comparison between the two 1, Kryo serialization is much smaller than the Hessian. (Kryo is better than Hessian) 2, because Kryo does not serialize the descriptive information of the class field, Kryo needs to load the filed of the class itself. This means that if the class is not registered in Kryo, or if the class is first serialized by Kryo, Kryo takes time to load the class (Hessian is better than Kryo) 3, because of the reason of 2, if the class has been kryo loaded, then Kryo saved the information of its class, You can quickly fill a byte array into the field of the class, and Hessian needs to parse the field information in the serialized byte array, Kryo is better than Hessian for the serialized class. 4, Hessian used fixed-length storage int and long, and Kryo is used for the longer, in practice, very large data will not appear frequently. (Kryo better than Hessian) 5, Hessian writes the serialized field length to determine the end of a field, while Kryo for string uses its last byte+x70 for the identity end (Kryo better than Hessian)      Summary: Object serialization, in fact, is an object, according to a certain rule into a byte array, and can follow the rules in the conversion back, the smaller the size of the serialization, the faster the general speed, of course, also depends on the algorithm and processing speed, but not necessarily suitable for various scenarios, Although the serialization of the JDK may be inefficient, it almost completely guarantees the accuracy of the results after deserialization. The serialization framework has many, encountered can look up the principle and sequence of the contents of the word, compared to see if they are suitable for themselves. There are also various evaluation of the performance comparison between the serial session framework.   Remember: When you learn Dubbo, the Dubbo default serialization is HESSIAN2 serialization (Hessian is a cross-language, efficient binary serialization method. But here is not actually the native hessian2 serialization, but Ali modified Hessian lite, which is Dubbo RPC enabled by default serialization method), and see Dubbox when the Dubbox introduced Kryo and FST Two efficient Java serialization implementation, To gradually replace the hessian2. (Kryo is a very mature serialization implementation that has been widely used in Twitter, Groupon, Yahoo, and many well-known open source projects such as Hive, Storm). While FST is a relatively new serialization implementation, there is still a shortage of mature use cases, but it is still very promising. In a production-oriented application, I recommend that Kryo be preferred at present. ) provides a brief description of theComparison of byte sizes after serialization of the same object by the serialization framework

----Content section excerpt from the network, if there is infringement, please contact.

Discussion on object serialization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.