12

I built an xml-rpc server in Python using SimpleXMLRPCServer, according to the example in the Python documentation. I'm calling it from a Python client on the same machine. The body of the server function executes very fast on its own.

But I find that xmlrpc client performance is excruciatingly slow, taking one second per call. (Using xmlrpclib.)

A speed-up technique I found on the web (skipping the getfqdn resolution) didn't help.

My connect URI is:

'http://localhost:50080'

I'm running Python 2.7 x64 on Windows 7, but it works the same for 32-bit Python 2.7.

1 Answer 1

29

The problem seemed to be with the client resolving localhost.

New (fast) connect URI:

'http://127.0.0.1:50080'

Similarly, adding this line in the hosts file %SystemRoot%\System32\drivers\etc\hosts has essentially the same effect:

127.0.0.1 localhost

Either of these changes increased the speed from 1 call/second to 88 calls/second, and skipping the getfqdn resolution might speed it up slightly more. Not extremely high-capacity, but acceptable for my application.

Correction: the new performance isn't 88 calls/second, but ~1000 calls/second.

2
  • Can confirm. Had this issue using PyMols xmlrpc server and it was very, very slow. Hosts file had the line 127.0.0.1 localhost commented. Simply uncommenting it solved the issue. Great!
    – beginner_
    Mar 3, 2016 at 5:39
  • 1
    NOTE: using localhost can be dangerous. If some sysadmin sticks "localhost.yourdomain.com" in some DNS server, boom... all your programs stop working. I prefer 127.0.0.1 ... directly. Apr 21, 2020 at 22:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.