Introducing Mprpc, a library for implementing fast RPC in Python.
Internally, it uses the MessagePack RPC protocol and existing [other language clients] such as Java, C ++, PHP, Ruby (https://github.com/msgpack-). Communication with rpc / msgpack-rpc) is also possible.
You can easily write an RPC server as shown below.
sum_server.py
from gevent.server import StreamServer
from mprpc import RPCServer
class SumServer(RPCServer):
def sum(self, x, y):
return x + y
server = StreamServer(('127.0.0.1', 6000), SumServer())
server.serve_forever()
When you define a method by inheriting the * RPCServer * class, the defined method is automatically registered as an RPC function.
sum_client.py
from mprpc import RPCClient
client = RPCClient('127.0.0.1', 6000)
print client.call('sum', 1, 2)
You can write the client like this.
$ python sum_server.py &
[1] 30945
$ python sum_client.py
3
Finally, compare performance with existing official MessagePack RPC implementations (based on Tornado) and dotCloud's ZeroRPC. I will try it. The code I'm using can be found here (https://github.com/studio-ousia/mprpc/tree/master/benchmarks).
% python benchmarks/benchmark.py
call: 9508 qps
call_using_connection_pool: 10172 qps
% pip install msgpack-rpc-python
% python benchmarks/benchmark_msgpackrpc_official.py
call: 4976 qps
% pip install zerorpc
% python benchmarks/benchmark_zerorpc.py
call: 655 qps
You can see that it runs about twice as fast as the existing MessagePack RPC client and about 14 times faster than Zero RPC.
Recommended Posts