Getting Started with GRPC Basics

  The rpc protocol framework is used in the project to implement the interface calls between the two systems. The A system calls the corresponding interface of the B system, because considering that the http request will contain more redundant information, causing the request to be too large, the grpc among the many rpc frameworks is selected. 

  grpc is google's open source rpc framework. The current version is 1.0.0. The jar package includes netty and okhttp. At the same time, protobuf is used in serialization (Google's self-developed serialization method - supports http2.0 and multiplexing, At the same time, the data is compressed, which is more efficient and cross-platform). Currently, protobuf in grpc uses the latest version 3.0 (except for some languages ​​that currently only support protobuf version 2).

1. Why use grpc

        RPC can be based on the TCP protocol or the HTTP protocol. The TCP-based RPC protocol is difficult to read and unfriendly. Although the amount of data is small and concise, if the data speed and IO requirements are not so high, the RPC based on the HTTP protocol can be used. Since gRPC is designed based on the HTTP/2 standard, compared with other RPC frameworks, gRPC brings more powerful functions, such as bidirectional streaming, header compression, and multiple multiplexing requests. These features bring significant benefits to mobile devices, such as saving bandwidth, reducing the number of TCP connections, saving CPU usage, and extending battery life. At the same time, gRPC can also improve the performance of cloud services and web applications. gRPC can be applied both on the client side and on the server side, so as to realize the communication between the client and the server side in a transparent manner and simplify the construction of the communication system.

 

2. Why use protobuf

        Protocol Buffers is a lightweight and efficient structured data storage format, which can be used for structured data serialization, and is very suitable for data storage or RPC data exchange format. 

        More efficient than json and xml, stored in an efficient binary format, 3 to 10 times smaller and 20 to 100 times faster than XML. The programming mode of Protobuf is friendly and easy to learn. 

        Two techniques ensure that programs using Protobuf can achieve significant performance gains over XML: 

        1. Protobuf serialized information content, the representation of information is very compact. 

        The binary message generated by Protobuf serialization is very compact, thanks to the very clever Encoding method adopted by Protobuf. 

        2. The general process of Protobuf encapsulation and unpacking, the speed of encapsulation and unpacking. 

        First, let's take a look at the XML encapsulation and unpacking process. XML needs to read the string from the file and convert it to the XML document object structure model. After that, read the string of the specified node from the XML document object structure model, and finally convert the string into a variable of the specified type. This process is very complex, in which the process of converting an XML file into a document object structure model usually requires the completion of complex and CPU-intensive computations such as lexical grammar analysis. 

        In contrast to Protobuf, it only needs to simply read a binary sequence into the structure type corresponding to the program according to the specified format. From the description in the previous section, we can see that the decoding process of the message can also be calculated by expressions composed of several displacement operations. speedy.

 

Article source: http://blog.csdn.net/lin6286878/article/details/52537717

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326049399&siteId=291194637