A brief introduction to Apache Thrift

Source: Internet
Author: User

1. What is Thrift

Thrift is a scalable software framework for the development of cross-language services. It combines a powerful software stack of code generation engines to build services. Services developed in different development languages can communicate through this framework.
Thrift was developed by Facebook,The creation of thrift is to solve the communication of large amount of data between systems in the Facebook system and the cross-platform characteristics of different language environments between systems. so thrift can support a variety of programming languages, such as: C + +, C #, Cocoa, Erlang, Haskell, Java, Ocami, Perl, PHP, Python, Ruby, Smalltalk. Communication between many different languages Thrift can be used as a binary high-performance communication middleware that supports data (object) serialization and multiple types of RPC services. Thrift defines the data types and services through the Interface Definition language (interface definition Language,idl), and the Thrift interface definition file is generated by the thrift code compiler to thrift the target language code (currently supported C++,java , Python, PHP, Ruby, Erlang, Perl, Haskell, C #, Cocoa, Smalltalk, and OCaml), and the generated code is responsible for the implementation of the RPC protocol layer and the Transport layer.
as an input file, the compiler generates code to easily build a seamless cross-programming language for RPC client and server communication . In short, developers simply need to prepare a copy of the thrift script that generates the required development language code by Thrift Code generator (entering a command like GCC)

How does 2.thrift work?

>>> defines the thrift file, which is generated by the thrift file (IDL), which generates both the interface and model of the two languages, and the encoded code is decoded in the generated model and interface.
>>>thrift File Examples
thrift-0.7.0.exe-r-gen java testthrift.thrift java code generation
thrift-0.7.0.exe-r-gen php testthrift.thrift generate PHP code
thrift-0.7.0.exe-r-gen py testthrift.thrift generate python code
thrift-0.7.0.exe-r-gen AS3 testthrift.thrift generate AS3 code
thrift-0.7.0.exe-r-gen CPP Testthrift.thrift generates C + + code.

3.Thrift protocol stacks and the use of each layer


model   interface
       Service invocation interface and interface parameters model, return value model
tprotocol    protocol layer
          Encode and decode the data (model).
Ttransport Transport Layer
         encoded data transfer (simple socket, HTTP)
Tserver
          service Tserver types, implementing several RPC calls (single threaded, multi-threaded, non-blocking IO)

protocol:

Thrift can let the user choose the type of transmission communication protocol between client and server, divide the transmission protocol into text and binary (binary) transmission protocol, in order to save bandwidth, improve transmission efficiency, and generally use binary type transmission protocol as the majority, Sometimes a text type-based protocol is used, depending on the actual requirements in the project product. Common protocols include the following:

tbinaryprotocol--binary encoded format for data transfer

Use the method as shown in Listing 3 and listing 4.

tcompactprotocol--high-efficiency, dense binary encoding format for data transfer

The servers and clients that build the TCOMPACTPROTOCOL protocol simply replace the TBINARYPROTOCOL Protocol section in Listing 3 and listing 4.

tjsonprotocol--using JSON Data encoding protocol to build the Tjsonprotocol protocol server and client simply replace the TBINARYPROTOCOL Protocol section in Listing 3 and listing 4

tsimplejsonprotocol--only provides JSON-only protocols for parsing through scripting languages

Transport Layer:

tsocket--is the most common mode of transmission using blocking I/O

Use the method as shown in Listing 4.

tframedtransport--is transmitted in a block size, similar to NIO in Java, using a non-blocking method

If the Tframedtransport transport layer is used, its server must be modified to a non-blocking service type.

A brief introduction to Apache Thrift

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.