使用tornado ioloop的小型异步tcp和双工rpc实现。
torpc的Python项目详细描述
torpc(tornado+rpc)是在 基于tornado ioloop的python。它很轻很高 性能(尤其是在pypy上)。
注意:torpc只在CPython 2.7+和^{tt2}上进行了测试$ 直到现在。
##示例
rpc服务器
fromtornadoimportioloopfromtorpcimportRPCServerserver=RPCServer(('127.0.0.1',5000))@server.service.register()defecho(x):returnxserver.start()ioloop.IOLoop.instance().start()
rpc客户端
fromtornadoimportioloop,genfromtorpcimportRPCClientdefresult_callback(f):print(f.result())@gen.coroutinedefusing_gen_style():want_to_say='way to explore'ret=yieldrc.call('echo',want_to_say)assertret==want_to_sayprint('gen_style complete')rc=RPCClient(('127.0.0.1',5000))rc.call('echo','hello world',callback=result_callback)future=rc.call('echo','code for fun')future.add_done_callback(result_callback)using_gen_style()ioloop.IOLoop.instance().start()
请参阅examples中的更多内容。
性能
操作系统:CentOS 6.6 x64 CPU:Intel i5-3470 3.20GHz 内存:8 GB 1600 MHz DDR3 Python:2.7.10 Pypy:4.0.0
environment | call coroutine(qps) | callback(qps) |
---|---|---|
Python(with timeout) | 9842 | 11614 |
Python | 13192 | 16638 |
PyPy(with timeout) | 40486 | 41225 |
PyPy | 53252 | 59151 |
PyPy(unix domain) | 67100 | 74362 |
在这个基准测试中,python循环10万次,pypy循环10万次, 然后每次运行3次,结果在gist:benchmark_result.txt