Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

JSON, Protobuf, Thrift, MessagePack comparison and Development Guide

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Advantages and disadvantages of mainstream serialization protocols and JSON recommended by websites

1 easy to use and low development cost

2 Cross-language

3 lightweight data exchange

4 non-verbose (compare xml tag with simple parenthesis closed loop)

Shortcoming

(1) large volume, affecting high concurrency

2 there is no version check, do compatibility by yourself

The process of creating and verifying 3 fragments is more complicated than that of general XML.

4 lack of namespaces leads to information mixing

Summary: the simplest and most general application protocol has the advantages of wide use, high development efficiency, relatively low performance and high maintenance cost.

Protobuf

Protobuf is a way to encode structured data in an efficient and extensible format.

Advantages

1 cross-language, customizable data structure.

2 fields are numbered, and the newly added fields do not affect the old structure. The problem of backward compatibility has been solved.

(3) automatic code generation, easy to use.

4 binary message, high efficiency and high performance.

5 Netty and other frameworks integrate the protocol and provide programming to improve development efficiency.

Shortcoming

1 binary format, poor readability (the data after grabbing the dump is difficult to understand)

(2) the objects are redundant, there are many fields, and the generated classes are large and take up space.

3 does not have dynamic characteristics by default (can be dynamically defined to generate message types or supported by dynamic compilation)

Summary: simple and quick to start, high efficiency and compatibility, high maintenance cost.

Reference website

Official website and guide

Https://developers.google.com/protocol-buffers/

Github

Https://github.com/protocolbuffers/protobuf

Research on Decoding and Packaging of protobuf Protocol by netty

Https://www.cnblogs.com/tankaixiong/p/6366043.html

Detailed explanation of protobuf development principles and defects

Https://my.oschina.net/cxh4905?tab=newest&catalogId=387288

Advantages of Thrift (Facebook)

1 Serialization and RPC support one-stop solution, which is more convenient than pb

2 Cross-language, IDL interface definition language, automatically generate multi-language files

3 save flow, small volume

4 contains a complete client / server stack for fast implementation of RPC

5 provides a variety of working modes for the server, such as thread pool model and non-blocking model

Shortcoming

1 there was a big problem in the earlier version, and there was a compatibility problem before 0.7

2 dual channels are not supported

3 rpc method is not thread-safe, the server is easy to hang and needs to be serialized.

4 does not have dynamic characteristics by default (can be dynamically defined to generate message types or supported by dynamic compilation)

5The development environment and compilation are troublesome.

Summary: cross-language, easy to implement, troublesome to use for the first time, need to avoid usage problems and scenario limitations.

Reference website

Thrift: The Missing Guide

Https://diwakergupta.github.io/thrift-missing-guide/

A beautiful encounter with Thrift

Https://www.cnblogs.com/cyfonly/p/6059374.html

From shallow to Deep understanding of Thrift (1)-- introduction and usage of Thrift

Https://blog.csdn.net/houjixin/article/details/42778335

MessagePack

Advantages

1 Cross-language, multi-language support (super many)

2 It's like JSON.but fast and small. Serialization and deserialization is efficient (twice as fast as json) and the file size is twice as small as json.

3 compatible with json data format

Shortcoming

1. Lack of complex model support. Msgpack doesn't have enough support for complex data types (List, Map), serialization is fine, but deserialization is troublesome, especially for java developers.

two。 The cost of maintenance is high. Msgpack locates attributes through the order of value, and needs to maintain the same model and the order of attributes in the model in different languages.

3. Model nesting is not supported. Msgpack cannot support including and nesting other custom models in the model (such as a list of comment in the weibo model).

Summary: high performance but poor scalability, high maintenance cost.

Reference website

Official website

Https://msgpack.org/

Msgpack-java

Https://github.com/msgpack/msgpack-java

MessagePack for C # translation

Https://www.cnblogs.com/stulzq/p/8039933.html

Principle analysis and application

Https://www.jianshu.com/p/8c24bef40e2f

Code

Https://www.programcreek.com/java-api-examples/?api=org.msgpack.MessagePack

Multi-protocol comparison

Serialization time comparison

Serialization size comparison

Comparison of serialization performance of go language

Https://github.com/smallnest/gosercomp

Performance comparison test results of various Java serialization libraries

Http://developer.51cto.com/art/201506/480273.htm

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report