客户端:
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
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