ToRPC RPC 的 Python 实现

程序名称:ToRPC

授权协议: MIT

操作系统: 跨平台

开发语言: Python

ToRPC 介绍

ToRPC(Tornado + RPC) 是一个的基于 Tornado IOLoop 的异步TCP和双向通信的RPC的Python实现。ToRPC非常轻量级,性能优秀(尤其是在PyPy环境下)。

注意:目前为止,ToRPC只在CPython 2.7+和PyPy 2.5+上测试过。

示例

RPC 服务器

from tornado import ioloop
from torpc import RPCServer
server = RPCServer(('127.0.0.1', 5000))

@server.service.register()
def echo(x):
    return x

server.start()
ioloop.IOLoop.instance().start()

RPC 客户端

from tornado import ioloop, gen
from torpc import RPCClient

def result_callback(f):
    print(f.result())

@gen.coroutine
def using_gen_style():
    want_to_say = 'way to explore'
    ret = yield rc.call('echo', want_to_say)
    assert ret == want_to_say
    print('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

Performance

系统: CentOS 6.6 x64

处理器: Intel i5-3470 3.20GHz

内存: 8 GB 1600 MHz DDR3

Python: 2.7.10 PyPy: 4.0.0

environmentcall coroutine(qps)callback(qps)
Python(with timeout)984211614
Python1319216638
PyPy(with timeout)4048641225
PyPy5325259151
PyPy(unix domain)6710074362

这个基准测试中,Python循环10w次,PyPy循环50w次,然后运行3次,结果在gist:benchmark_result.txt

ToRPC 官网

https://github.com/yoki123/torpc

相关编程语言

MuPlayer 是一款跨平台、轻量级的音频播放解决方案,...
OS FLV 是一个 开源和可嵌入网页的flv播放器。 这个...
DewPlayer音乐播放器,样式很简单,而且很实用.播放器...
JW FLV MEDIA PLAYER是一个开源的在网页上使用的Fla...
Speakker 是一个基于 Web 浏览器的音乐播放器,只提...
Player Framework 是一个开源的支持 HTML5 的视频播...