Thrift Tprotocol Class System principle and source code detailed: Dense protocol class Tdenseprotocol

Source: Internet
Author: User
Tags compact integer advantage

This protocol class does not recommend putting into the actual production environment (unless you do a very strong pressure and comprehensive testing). The biggest effect of this compact protocol is to use as little space as possible, the dense protocol class has two types of instance objects, one that is independent, is not used in RPC traffic, but is used for encoding and decoding, and a separate instance type that can be used for RPC traffic, but it does not yet support instances of this type.

The use of this dense protocol class for encoding and decoding must support thrift's own implementation of a special record data type form: The Type_spec attribute, whose main function is to localize the reflection mechanism to read and write data.

The best practice approaches are as follows:

(1) Never use an optional primitive or container type;

(2) If the data type is very large or very sparse, then use the struct type (struct);

(3) All integer types use variable length, can use i64 type to avoid expansion;

(4) Never modify the definition of the structure in any way without changing the key, otherwise it will cause a panic error.

This dense protocol class inherits to the binary protocol class, so you can use some protocol methods of the binary protocol class directly.

So what is the advantage and disadvantage of this Protocol class compared to the previous protocol class? Since this protocol class is gradually developed, then it must have its own advantages and appropriate application scenarios, as far as I learn, its advantages are as follows:

(1) compared to the binary protocol it uses variable length encoding, and of course the compact Protocol class also implements this to reduce the transmission of integer data, so what is its advantage over compact protocol classes? Take a look at the following article;

(2) relative to the Compact protocol class It reduces the transmission of a part of the metadata, such as the struct structure inside the field ID and data type, so that greatly reduce the flow, of course, the speed of naturally improved a lot.

Although it has these advantages, but its shortcomings are also more obvious, mainly has the following three points:

(1) The abstraction will lose its effect;

(2) A second code generator must be maintained;

(3) It would be very difficult to maintain compatibility with older versions.

Through its advantages and shortcomings of the analysis found that they are so bright, so the choice of this Protocol as a transport layer on the protocol type needs to be considered more carefully, the advantage is the sacrifice of abstraction, easy maintenance and forward compatibility to improve data transmission speed and reduce traffic.

So what special techniques are needed to implement this Protocol class, with code and annotations found, the main two-point technology, one is variable-length coding, which has been implemented and introduced in the Compact Protocol class, and another technique is to eliminate some of the transmitted metadata. Eliminating the transfer of metadata requires support for thrift compilers and sacrificing forward and backward compatibility of some binary protocols.

The above analyses the excellent and insufficient of the dense protocol class, but for now, this class is still in the test phase, can not put into the real production environment, so do not specifically analyze the implementation of the code, interested colleagues can see the implementation of the Code, the use of the technology has been introduced before.

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.