What is claire-protorpc
protobuf-based RPC library
for x86-64 Linux
● In computer telecommunications, echo is the display or
return of sent data at or to the sending end of a
transmission. ------ from wikipedia
● Use claire-protorpc develop application and services
○ define a .proto file which declared the rpc message
structure and methods
○ use generated stub to call echo methods through
○ implement echo services, and register it to RpcServer
● echo.pb.h define Stub
which can call Echo
● It need RpcChannel to
int main(int argc, char* argv)
InetAddress server_address(argv, 8080);
RpcControllerPtr controller(new RpcController());
stub.Echo(controller, request, boost::bind(&replied, _1, _2));
● echo.pb.h define
EchoService, server side
need implement it.
● EchoService need
register to RpcServer.
int main(int argc, char* argv)
::google::ParseCommandLineFlags(&argc, &argv, true);
RpcServer server(&loop, listen_address);
Benefits of claire-protorpc
● claire-protorpc provide:
Define a service only need a function.
Generate stub to call remote service.
Automatic message encode/decode.
Checksum for each message.
Compress data if user set.
Very good performance, at least no obvious
protobuf provide server declaration but no implementation, it suggest
“provide code generator plugins which generate code specific to the
particular RPC implementation.”
claire-protorpc is one implementation of protobuf-based rpc, and supply
itself plugin to generate code for claire-protorpc only.
It implement 3 important concept of protobuf rpc:
But we do not use Google defined interface directly, instead claire-version!
Services themselves are abstract interfaces (implemented either by servers
or as stubs), but they subclass this base interface. The methods of this
interface can be used to call the methods of the Service without knowing
its exact type at compile time (analogous to Reflection).
claire-protorpc use protoc-rpc-gen to generate the rpc service which
inherited from Service class(claire-protorpc’s version)
● “An RpcController mediates a single method call. The
primary purpose of the controller is to provide a way to
manipulate settings specific to the RPC implementation
and to find out about RPC-level errors.”
● Now it used to declare caller specific option and get error
● “An RpcChannel represents a communication line to a
Service which can be used to call that Service's methods.
The Service may be running on another machine.
Normally, you should not call an RpcChannel directly,
but instead construct a stub Service wrapping it.”
● Now it used to communicate to RpcServer, it do message
encode/decode, health detection, compress/uncompress,
loadbalance, address resolverm, .etc .
● RpcServer used to store all registered service, and
response to all request.
○ It also provide monitor, debug, profile, flags
management features, user no need write one line
code to use these
claire-protorpc supply powerful metrics type:
■ A counter is a value that never decreases. Examples might be
"sent bytes" or "receied bytes". You just increment the counter
each time a countable event happens, and graphing utilities
usually graph the deltas over time.
■ A metric is tracked via distribution, and is usually used for
claire-protorpc support graphing pages & json interface together
● claire-protorpc integrate with gperftools, so
it support online profiling.
○ support /pprof/profile, /pprof/heap, /pprof/growth
○ also support profile without binary file, through
/pprof/symbol & /pprof cmdlind
○ will support /pprof/contension later