ToRPC 正在参加 2021 年度 OSC 中国开源项目评选,请投票支持!
ToRPC 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
2021 年度 OSC 中国开源项目评选 正在火热进行中,快来投票支持你喜欢的开源项目!
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
ToRPC 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !
授权协议 MIT
开发语言 Python 查看源码 »
操作系统 跨平台
软件类型 开源软件
开源组织
地区 国产
投 递 者 toil
适用人群 未知
收录时间 2015-11-16

软件简介

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

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循环10w次,PyPy循环50w次,然后运行3次, 结果在gist:benchmark_result.txt

展开阅读全文

代码

的 Gitee 指数为
超过 的项目

评论

点击加入讨论🔥(1)
暂无内容
发表了博客
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
发表了问答
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
暂无内容
1 评论
89 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部