XML-RPC

159 views
Skip to first unread message

Marcus Ottosson

unread,
May 20, 2015, 11:11:46 AM5/20/15
to python_in...@googlegroups.com

Does anyone have experience with it? What are your thoughts, compared to other forms of RPC?

I found it hidden away amongst the default Python libraries and am quite astounded by it’s simplicity.

# From within Maya
from SimpleXMLRPCServer import SimpleXMLRPCServer
import threading

from maya import cmds

server = SimpleXMLRPCServer(("127.0.0.1", 8000))
server.register_function(cmds.createNode)

t = threading.Thread(target=server.serve_forever)
t.daemon = True
t.start()

And then, from a terminal.

>>> import xmlrpclib
>>> proxy = xmlrpclib.ServerProxy("http://127.0.0.1:8000/")
>>> proxy.createNode("mesh")
'polySurfaceShape1'

Resources:

--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
May 20, 2015, 3:57:17 PM5/20/15
to python_in...@googlegroups.com

I don't have much to say in either direction, since I have never used the builtin xml-rpc in my own server/client solution. But I think I used it once to connect to an instance of supervisor (the python-based process manager), which does expose an xml-rpc endpoint so that you can control it. Seems like xml-rpc is probably a lower performance solution that is good when you just need to send less frequent calls. Since it uses xml and makes httprequests, it has extra overhead in both the connection and the protocol.
Also, I think the builtin server in the python standard lib might be there for lower performance needs. The server isn't a serious production grade and most likely handles a single request at a time. I believe it also fully tears down the connection after each call, as opposed to solutions that could use keep-alive.

But it probably works just fine for the situation you outlined, where you are sending control commands to a local Maya. I doubt you would want to stand up a server and hit it with 10 clients.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBOaQfQ0k2_dLavXb0zDOOR6%2Bt%2Bb%3DpjWz7mMdrBWKDvTw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
May 20, 2015, 4:33:55 PM5/20/15
to python_in...@googlegroups.com
Thanks Justin.

It does actually support concurrent responses, both threaded and forked, so I wouldn't be surprised if it could scale quite a bit as-is.

On my machine, it handles around 1600 (synchronous) requests/second.

Out of curiosity, I'll have a quick look to see what threading or forking can do about it. Alternatively, I also found this, but the main attraction to me is standard library inclusion.

Justin Israel

unread,
May 20, 2015, 4:50:30 PM5/20/15
to python_in...@googlegroups.com
Awesome. I only glanced at the standard library implementation, and it seemed pretty basic. So if it gets you the performance you are after, then that solves a problem. 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

Marcus Ottosson

unread,
May 21, 2015, 2:08:50 AM5/21/15
to python_in...@googlegroups.com

I wasn’t really having any problems with it, I was more wondering whether any of you had had any experience with it.

Considering it’s from 2001-2002, has a rather ugly import (with non-PEP08 names) spread across two top-level modules (for client and server) and contains the word “XML”, I can understand how a first impression might have gotten spoiled.

But it looks and works great.

It also supports batched calls; as in gathering up any number of RPC and sending them through a single request. I wish I came across this ages ago. :O

Some tests, with a single provider and consumer. Not fair, probably, it should probably use multiple consumers to show a difference here, but singles is all I’m looking for personally.

Synchronous 1600/sec

from SimpleXMLRPCServer import SimpleXMLRPCServer
import SocketServer

def null():
    return True

server = SimpleXMLRPCServer(("0.0.0.0", 80), logRequests=False)
server.register_function(null)
server.serve_forever()

Threaded 1222/sec

from SimpleXMLRPCServer import SimpleXMLRPCServer
import SocketServer

def null():
    return True

class ThreadedServer(SocketServer.ThreadingMixIn, SimpleXMLRPCServer):
    pass

server = ThreadedServer(("0.0.0.0", 80), logRequests=False)
server.register_function(null)
server.serve_forever()

Forked 380/sec

from SimpleXMLRPCServer import SimpleXMLRPCServer
import SocketServer

def null():
    return True

class ForkingServer(SocketServer.ForkingMixIn, SimpleXMLRPCServer):
    pass

server = ForkingServer(("0.0.0.0", 80), logRequests=False)
server.register_function(null)
server.serve_forever()

Test

$ python -m timeit "import xmlrpclib;p = xmlrpclib.ServerProxy('http://192.168.131.153:8000');print p;[p.null() for x in xrange(100)]"


For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
May 21, 2015, 2:21:41 AM5/21/15
to python_in...@googlegroups.com
Ya like I said, I didn't have any concrete experience to offer. It seems like it will work great for your use case.  And if you needed multiple clients to be able to connect, and they all handle reasonably well, then why not. 



Marcus Ottosson

unread,
May 21, 2015, 2:30:37 AM5/21/15
to python_in...@googlegroups.com

I just discovered this, gives some perspective to the performance of the built-in Python version.

Using C, a client program starts (exec()), does 100 RPCs, and exits in 380 milliseconds. With just one RPC, it’s 26 ms. By calculation, this means the time for just an RPC is about 4 ms, about 280 RPCs per second.

A tad sceptical that Python outperforms C though. :S



For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
May 21, 2015, 2:38:04 AM5/21/15
to python_in...@googlegroups.com
Interesting info. It talks about one of its implementations eliminating the use of http. Although the standard python lib one, I believe uses an http protocol. Also, if you aren't using that multicmd thing, then I believe each http connection is fully torn down each time. 

Marcus Ottosson

unread,
May 21, 2015, 2:48:26 AM5/21/15
to python_in...@googlegroups.com

then I believe each http connection is fully torn down each time.

What does that mean? Is it of performance concern, or something else?



For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
May 21, 2015, 2:54:58 AM5/21/15
to python_in...@googlegroups.com
On Thu, May 21, 2015 at 6:48 PM Marcus Ottosson <konstr...@gmail.com> wrote:

then I believe each http connection is fully torn down each time.

What does that mean? Is it of performance concern, or something else?



And an example, in practice, via the python requests library:

The idea being that if you can keep your http connection alive, then it can wait for the next request and avoid the whole set up and tear down of a full http connection. But when I glanced at the source for the SimpleXMLRPCServer, it seemed to completely shutdown the connection after each request. This just means its not a fancy server, as indicated by the "simple" prefix. 
 

Marcus Ottosson

unread,
May 21, 2015, 3:06:21 AM5/21/15
to python_in...@googlegroups.com
Ah, thanks. I'll have a look through those links.


For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

zhen huang

unread,
Jan 27, 2018, 9:14:08 AM1/27/18
to Python Programming for Autodesk Maya
Hi Marcus , Justin , 

If I just want to use it as remotely standalone mayapy which control by my currently GUI maya . how can I register all maya command inside ? ( The purpose is to fully remotely control the standalone mayapy ) ,  appreciate if you guys can answer this question from a junior , thanks a lot !

在 2015年5月20日星期三 UTC+8下午11:11:46,Marcus Ottosson写道:

Marcus Ottosson

unread,
Jan 27, 2018, 9:24:45 AM1/27/18
to python_in...@googlegroups.com

Without having tested this, and it being 3 years since I first wrote it, something like this might do the trick.

Replace this..

server.register_function(cmds.createNode)

With this..

for function in dir(cmds):
  server.register_function(getattr(cmds, function))

Now you’ll have registered every single function in cmds and should be able to call them remotely.

Use at your own risk! :)

Zhen Huang

unread,
Sep 26, 2018, 2:17:40 AM9/26/18
to Python Programming for Autodesk Maya
Hi Marcus , 

Awesome!  

Thanks , 


在 2018年1月27日星期六 UTC+8下午10:24:45,Marcus Ottosson写道:
Reply all
Reply to author
Forward
0 new messages