About Google Grpc

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. about Google Grpc

1. Introduction

Google has just open source Grpc, an RPC implementation based on HTTP2 and Protobuf.

Where GitHub address: HTTPS://GITHUB.COM/GRPC/GRPC

Although PROTOBUF itself provides the definition of RPC syntax, but all along, Google has only open source Protobuf serialization deserialization code, without the implementation of open source RPC, so there are many mixed third-party RPC implementations.

In terms of implementations and features, GRPC is more about the client and server communication in the case of mobile scenarios, as its self-proclaimed "general RPC framework that puts mobile and HTTP/2 first". The HTTP2 itself provides mechanisms for connecting multiplexing, Body, and Header compression, which GRPC based on to provide a more efficient implementation.

The dependencies used by GRPC are relatively new, such as PROTBUF requires version 3.0, C + + uses c++11, Netty in Java implementations requires 5.0, and HTTP2 is just finalized. Many of these dependencies are still not formally released, so for the time being, GRPC is not a stable state to use.

GRPC provides native implementations of C, Java, Golang, and supports node. js, Python, Ruby, Objective-c, PHP, and C # languages in C shared libraries (from this perspective, C + +, Java, and Golang in Google Have the status of a class citizen). The implementation of Java language can also be used for Android clients, the implementation of OBJECTIVE-C primarily for iOS clients.


2. Protocol Analysis

GRPC differs from the usual TCP-based implementation, and is directly based on the HTTP2 protocol. HTTP2 enables GRPC to be better suited for use scenarios for mobile client and server-side communication, and connectivity multiplexing also guarantees RPC efficiency.

The GRPC protocol is well designed to use the HTTP2 existing semantics, the request and response data is sent using HTTP Body, and the other control information is represented by the header. Let's look at an example, assuming that PROTOBUF is defined as follows:

Package Foo.bar;message hellorequest {  string greeting = 1;} Message Helloresponse {  string reply = 1;} Service HelloService {  rpc SayHello (hellorequest) returns (Helloresponse);}

In this case, we define a service HelloService. GRPC the request sent for such a call is:

HEADERS(Flags =End_headers): Method=Post:scheme=Http:path=/foo.bar.helloservice/sayhello:authority=Api.test.comgrpc-timeout=1scontent-type=Application/grpc+protogrpc-encoding=GzipAuthorization =Bearer Y235.wef315yfh138vh31hv93hv8h3vdata(Flags =End_stream)<delimited message>

The path portion of the Http request is used to indicate which service is called, in the format/{package}. {Servicename}/{rpcmethodname},content-type currently values are Application/grpc+proto, there will be other values in the future GRPC support for protocols other than PROTOBUF, such as JSON. Grpc-encoding can have gzip, deflate, snappy and other values, indicating the compression method used. Grpc-timeout represents the time-out of the call, in units with hour (H), Minute (M), Second (S), millisecond (m), microsecond (U), nanosecond (n), and so on.

In addition to the standard headers defined by GRPC, you can add a new header yourself. If it is a binary header, the header Name ends with-bin, and header Value is a BASE64 encoded binary data. The server returns a response for this request:
HEADERS(Flags =End_headers): status=200grpc-encoding=Gzipdata<delimited message>headers(Flags =End_stream, End_headers)Grpc-status= 0 # OKTrace-proto-bin=Jher831yy13jhy3hc
A grpc-status of 0 indicates that the request did not appear to be a problem and returned successfully. GRPC also defines the Goaway Frame, which is required to send a message to the client when the server disconnects a connection, and a ping frame that receives a ping frame and returns data directly as it is used to connect survival detection and latency detection. The header of HTTP2 is not a particularly efficient format, and there are some efficiency issues on storage and parsing. If you enable encrypted connections, you will have more efficiency overhead.

Reference: http://www.dongliu.net/post/622451
Related Article

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.