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):

   # 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(("",
   print "running in xmlrpc mode"

   print "The daemon runs on port:",daemon.port
   print "The object's uri is:",uri

client benchmark code

import Pyro.core
import xmlrpclib, os, sys

if sys.argv[1] == "xmlrpc":
   rpctest = xmlrpclib.Server("")
   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