[Twisted-Python] How to accept connections faster
bob at redivi.com
Wed Mar 16 05:39:48 EST 2005
On Mar 16, 2005, at 5:21, Sinang, Danny wrote:
> I ran the (Twisted) server code below and it accepts a client socket
> connection every 1.3 seconds. The equivalent Synchronous socket code
> accepts one every 2 seconds.
> Can anyone here suggest any code improvements for my Twisted server to
> accept connections faster ?
> for i in range(10000000):
> print "Looping done."
That is blocking code and is not suitable for usage in a Twisted server
if you expect good performance. All functions that run in the
reactor's thread should be designed to return quickly so that Twisted
can handle events quickly. You either need to refactor it to run
iteratively (via successive callLater, LoopingCall, etc.), or in
another thread (deferToThread).
More information about the Twisted-Python