Access thrift

thrift is a RPC framework used widely in various environments, which was developed by Facebook and adopted by Apache later. In order to interact with thrift servers and solves issues on thread-safety, usabilities and concurrencies, brpc directly supports the thrift protocol that is used by thrift in NonBlocking mode.

Example: .

Advantages compared to the official solution:

  • Thread safety. No need to set up separate clients for each thread.
  • Supports synchronous, asynchronous, batch synchronous, batch asynchronous, and other access methods. Combination channels such as ParallelChannel are also supported.
  • Better performance.

Compile

brpc depends on the thrift library and reuses some code generated by thrift tools. Please read official documents to find out how to write thrift files, generate code, compilations etc.

Install thrift under Linux Read to install depended libs and tools, then download thrift source code from official site, uncompress and compile。

Config brpc with thrift support, then make. The compiled libbrpc.a includes extended code for thrift support and can be linked normally as in other brpc projects.

Read for more compilation options.

Client accesses thrift server

Steps:

  • Create a Channel setting protocol to brpc::PROTOCOL_THRIFT
  • Create brpc::ThriftStub
  • Use native request and response to start RPC directly.

Server processes thrift requests

Inherit brpc::ThriftService to implement the processing code, which may call the native handler generated by thrift to re-use existing entry directly, or read the request and set the response directly just as in other protobuf services.

Set the implemented service to ServerOptions.thrift_service and start the service.

Performance test for native thrift compare with brpc thrift implementaion

Test Env: 48 core 2.30GHz