Fri, 30 Dec 2005
RPC in Python - a comparison of Pyro and xmlrpc
I have been dabbling in rpc on python, after removing a home brew rpc system using pickle and unix domain sockets and replacing it with something more network aware. xmlrpc is cool, but seemed to be a bit slow. Poking around I found Pyro, which looked good and also passed my test of a server taking just a few lines of code to create.So I made some test code using some ultra simplified versions of my rpc class methods that can work with either RPC scheme depending on the command line args. The results of timing the below code is that for this test, Pyro is 18 times faster. There are of course the various caveats about Pyro's security, and the standards compliance and interoperability of xmlrpc, so its also a case of different horses for different courses.
Also maybe handy as a simple example of xmlrpc and Pyro rpc under Python:
server code
import Pyro.core
import SimpleXMLRPCServer
import os, sys
class rpctest(Pyro.core.ObjBase):
def __init__(self):
Pyro.core.ObjBase.__init__(self)
# get a file.. simple version
def getfile(self,file):
filedata = open(file,"r").read()
return filedata
def listdir(self,dirname):
listdirresults = os.listdir(dirname)
return listdirresults
if sys.argv[1] == "xmlrpc":
server = SimpleXMLRPCServer.SimpleXMLRPCServer(("",
8000),logRequests=False)
server.register_instance(rpctest())
print "running in xmlrpc mode"
server.serve_forever()
else:
Pyro.core.initServer()
daemon=Pyro.core.Daemon()
uri=daemon.connect(rpctest(),"rpctest")
print "The daemon runs on port:",daemon.port
print "The object's uri is:",uri
daemon.requestLoop()
client benchmark code
import Pyro.core
import xmlrpclib, os, sys
if sys.argv[1] == "xmlrpc":
rpctest = xmlrpclib.Server("http://192.168.1.1:8000")
else:
rpctest =
Pyro.core.getProxyForURI("PYROLOC://192.168.1.1:7766/rpctest")
for i in range(1000):
print len(rpctest.getfile("/etc/passwd"))
print len(rpctest.getfile("/etc/group"))
print len(rpctest.listdir("/usr/bin"))
Posted at: 23:22 | category: /nerdy | # | 0 comments
