[Twisted-Python] Question regarding async stuff

Itamar Shtull-Trauring twisted at itamarst.org
Wed Jul 10 19:53:18 MDT 2002


Greg Fortune wrote:

> The reason I ask is that it doesn't appear that a twisted server can handle 
> processing multiple requests at the same time.  It appears that a request 
> must come in and be processed before another request can be serviced.  It 
> probably isn't a big deal for me as the number of requests and amount of 
> processing per request will be low, but it could be that I'm totally 
> misunderstanding how the framework works.  

Well, consider this - unless you have a SMP machine, your computer can 
only do one thing at a time anyway. So, serving more than one request is 
  just a matter of how you give time to handling different tasks - 
there's no one way you can really do more than one thing at once.

The idea then is to do a little bit each time we get a dataReceived 
callback, and finish up as quickly as possible so we can move on to 
handling the next event. We can also use stuff like producers and 
reactor.callLater to create events even when we aren't getting data from 
the network. In each event handler though we need to make sure we don't 
block.

And yes, this can work. For example this is how Squid works, and Squid 
is rather fast and can do more than one HTTP request "at once".

Recommended reading:
http://www.cs.wustl.edu/~schmidt/PDF/reactor-siemens.pdf





More information about the Twisted-Python mailing list