Grpc vs Thrift

Source: Internet
Author: User
Tags documentation extend php and cpu usage
Simple Distributed Architecture


Basic questions
What kind of data is transferred, which protocol is the efficiency of the data exchange? How the server handles the request needs to extend the server when your service exceeds the simplest structure, you want to

Flexibility to extend low latency of course, do you want to use these protocols more simply? SOAP
XML, XML, or XML CORBA
Good ideas, poor implementation of transitional design and bloated


DCOM, COM + is primarily used for Windows platform Http/tcp/socket/whatever
Proven but lack of protocol processing
Need to implement their own protocols to encapsulate their own implementation of the client, the service side of the underlying protocol and status

So what do we need?

Transparent interaction between different languages
Platform and language independent can be well balanced
Efficiency (time, space) development ease-of-use and execution speed using existing class libraries

Introduction to RPC programming

Remote Procedure Call (remotes Procedure CALL,RPC)
is a computer communication protocol. The protocol allows programs running on one computer to invoke subroutines from another computer, and programmers do not need to program this interaction for additional purposes. Why RPC is selected
To improve development efficiency, developers can focus more on specific interface implementations without having to consider the underlying transmission of data. Most RPC frameworks are the crystallization of the wisdom of many good developers, and their ability to implement and execute efficiently is excellent. The client side and server side must follow a uniform interface specification to avoid creating a mismatch between client and server interface or data bureau structure.Google GrpcGrpc
GRPC is a high-performance, general-purpose, open-source RPC framework created by Google
2015 primarily for mobile application development and based on the HTTP/2 protocol standard, based on PROTOBUF (Protocol
Buffers) serialization protocol development and support for a wide range of development languages. GRPC provides an easy way to precisely define services and automatically generate a highly reliable client function library for iOS, Android, and background support services. Clients take advantage of advanced streaming and linking capabilities to help conserve bandwidth, reduce TCP links, save CPU usage, and battery life. Latest Google API support GRPC support C, C + +, node. js, Python, Ruby, objective-c,php and C # current version Alpha Protocol BSD PROTOBUF
It was designed by Google 2001 and open source in 2008. Google's internal services are almost always using the PB protocol proven, fully validated, well-implemented
-Use Protobuf:google, Hadoop, ActiveMQ, Netty current version v3.0.0-alpha-3 protocol BSD

Apache Thrift

Thrift is a scalable RPC software framework for cross-language services. It combines the code generation engine of a powerful software stack to build services that are efficient and seamlessly used across multiple languages. It was a top-notch project under Apache, which was contributed by Facebook to the Apache Fund in 2007. Supports C, C + +, C #, D, Delphi, Erlang, Go, Haxe, Haskell, Java, JavaScript
, node. js, OCaml, Perl, PHP, Python, Ruby, SmallTalk use Thrift:hadoop, HBase, Cassandra, Scribe, LastFM, Facebook, Evernote Current version 0.9.2 protocol Apache License 2.0

Typical operation model

Idl-like language Definition Interface run tool generates Java, Python, go and other reference programs
such as: Thrift–gen go myproject.thrift generated by the reference program even more, are readable in their own programs to reference the generated program


Do not edit! Tthritr Operating principle



GRPC implementation principle similar to Interface Definition Language (IDL)



Grpc




Syntax = "Proto3";  PROTOBUF3 Agreement package
infg;

option Optimize_for=speed;

Message person {
    string name = 1;
    Map<string, int64> tel = 2;
}
Message Mediarp {
    string uri = 1; 
    string title = 2;
    Int32 width = 3; 
    Int32 height = 4; 
    Repeated person person = 5; 
    Enum Player {
        JAVA = 0;
        FLASH = 1;
    }
    Player player = 6; 
}
Message Mediarq {
    string uri = 1;
}

Service Media {
    RPC media (MEDIARQ) returns (Mediarp);
}


Thrift




Namespace go inft

typedef i32 INT;
typedef i64 Long;

Enum Player {
    JAVA = 0;
    FLASH = 1;
}
struct Person {
    1:required string name;
    2:optional map<string, long> tel;
}
struct Mediarp {
    1:required string uri; 
    2:optional string title;
    3:required int width;
    4:required int height;
    5:required list<person> person;
    6:required player player;
struct Mediarq {
    1:required string uri;
}

Service Media {
    Mediarp media (1:mediarq Mediarq);
}

IDL Rules

Each column must have a unique positive integer identifier thrift each column can be identified as "optional", "required", PB can not, each column is "optional" GRPC service, must have input and output, and the parameter and return value must be a defined message type, and in thrift, both the input and output can be empty, and the parameter can be a defined struct or other supported type Structs/messages can contain other structs/ Messages each column can have a "default" value in the same file, and multiple structs/messages can be referenced to introduce additional files to define an integer identifier

"= 1", "= 2" or "1:", "2:", uniquely identifies a column in the binary to keep the digital ID constant very important number 1 to 15 occupy a byte number 16 to 2047 occupy two bytes keep 1 to 15 for most frequently used fields 


Compare








Test environment:
116 Do the RPC server, 118 as server, RPC client
116 24 Core CPU 128G memory, 118 32 core CPU 196G memory,
Million Gigabit network Multi- version system should support multiple versions, even if the old client calls the new server, or conversely in thrift and protobuf, the multi-version is a field identifier implemented by the field in use, do not update the integer identifier can delete the field is not used, The original identifier can be divided into other fields PB in [Deprecated=true] identifies the obsolete field field identifier and the field type uniquely identifies a field that does not need to recompile the new version how to choose when should choose GRPC instead of thrift
Need good documentation, sample likes, habits HTTP/2, protobuf to network transmission bandwidth when you should choose thrift instead of GRPC
Need to exchange data between a very large number of languages the CPU-sensitive protocol layer, the transport layer has a variety of control requirements need a stable version does not require good documentation and sample reference



GRPC official website http://www.grpc.io/
Thrift Official Website http://thrift.apache.org/
Pb vs Thrift VSF Avro Http://www.slideshare.net/IgorAnishchenko/pb-vs-thrift-vs-avro
Golang Grpc Example http://blog.csdn.net/dazheng/article/details/46544045
THRIFT VS. PROTOCOL buffers http://old.floatingsun.net/articles/thrift-vs-protocol-buffers/
Thrift User Guide http://dongxicheng.org/search-engine/thrift-guide/


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.