RPC 的 Python 实现 ToRPC

码农软件 · 软件分类 · RPC/XMLRPC项目 · 2019-04-11 14:11:41

软件介绍

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

本文地址:https://codercto.com/soft/d/3349.html

玩法变了

玩法变了

胖胡斐 / 电子工业出版社 / 2012-1 / 39.00元

《玩法变了:淘宝卖家运赢弱品牌时代》内容简介:目前网店的销售、运营、营销都碰到很多瓶颈,钱不再好赚,流量不再免费的情况下。网店常常陷入不断找流量的怪圈中,而真正潜心提升基本功的网店却拥有更多机会,网店需要突围。《玩法变了:淘宝卖家运赢弱品牌时代》系统地介绍整个电子商务零售领域的玩法变化,从网店基本功到网店品牌建设都有涉及。《玩法变了:淘宝卖家运赢弱品牌时代》将是网店用户重要的方法论和实践指南。一起来看看 《玩法变了》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

html转js在线工具
html转js在线工具

html转js在线工具