测试python rpc的性能

客户端:
import xmlrpclib,time
server = xmlrpclib.ServerProxy("http://localhost:8888")
for i in range(1,10):
a = time.time()
month = server.getMonth( 2002, i )
month = server.getMonth( 2002, i )
month = server.getMonth( 2002, i )
month = server.getMonth( 2002, i )
month = server.getMonth( 2002, i )
month = server.getMonth( 2002, i )
month = server.getMonth( 2002, i )
month = server.getMonth( 2002, i )
month = server.getMonth( 2002, i )
month = server.getMonth( 2002, i )
b = time.time()

print b-a
print month

服务器:
import calendar, SimpleXMLRPCServer
#The server object
class Calendar:
def getMonth(self, year, month):
return calendar.month(year, month)

def getYear(self, year):
return calendar.calendar(year)
calendar_object = Calendar()
server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8888))
server.register_instance(calendar_object)
#Go into the main listener loop
print "Listening on port 8888"
server.serve_forever()

结果:
0.077999830246
0.0310001373291
0.0469999313354
0.0310001373291
0.0469999313354
0.0309998989105
0.047000169754
0.0469999313354
0.0309998989105

基本上,每次请求的时间是0.03-0.04s
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值