Python's xmlrpc extremely slow: one second per call
Asked Answered
D

1

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.

Deliberative answered 24/1, 2013 at 15:6 Comment(0)
D
30

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.

Deliberative answered 24/1, 2013 at 15:6 Comment(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!Tiro
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.Goren

© 2022 - 2024 — McMap. All rights reserved.