[Twisted-Python] scaling with lots of clients

Itamar Turner-Trauring itamar at itamarst.org
Wed Aug 3 17:09:23 EDT 2011

> I have a twisted Perspective Broker based server. Recently with an
> increased number of clients we are seeing a decrease in throughput.
> Profiling the server it seems that it is spending the majority of time
> sending messages to the clients (unsuprisingly).

PyPy might speed this up quite a bit; http://speed.pypy.org suggests PyPy
can send PB messages 3 times as fast as CPython.

You could also switch to a protocol that has a faster serialization, which
shouldn't be too hard if your usage of PB is sufficiently simple.

> Messages are sent to the client from the server using a callRemote,
> invoked from the  event queue using reactor.callFromThread - nice and
> simple. What designs have people used to improve throughput in a heavily
> loaded server? My experience is telling me that I need to implement some
> sort of thread/process pool to divide the messaging to clients. Various
> documents on the twisted website strongly suggets that this is not a good
> idea.

Threading won't help much if you're CPU bound, since Python can only run
one Python thread at once. Process pooling probably would help, though
will involve a more complex infrastructure. Which part of the docs made
you think that process pooling is a bad idea?

More information about the Twisted-Python mailing list