Implement fast RPC in Python

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

Implement fast RPC in Python
Implement Enigma in python
Implement recommendations in Python
Implement sum in Python
Implement Traceroute in Python 3
Implement ancient ciphers in python
Implement Redis Mutex in Python
Implement extension field in Python
Implement method chain in Python
Implement Dijkstra's Algorithm in python
Implement Slack chatbot in Python
Implement stacking learning in Python [Kaggle]
Implement R's power.prop.test function in python
Implement the Singleton pattern in Python
Quickly implement REST API in Python
Quadtree in Python --2
Python in optimization
CURL in python
I tried to implement PLSA in Python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Implement __eq__ etc. generically in Python class
Meta-analysis in Python
Unittest in python
Implement FIR filters in Python and C
Collectively implement statistical hypothesis testing in Python
I tried to implement PLSA in Python 2
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
N-Gram in Python
Programming in python
Plink in Python
I tried to implement ADALINE in Python
Constant in python
I tried to implement PPO in Python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python