[Twisted-web] connection pool
Drew Perttula
drewp at bigasterisk.com
Fri Jan 18 01:06:16 EST 2008
Tjerk.Kusters at imtech.nl wrote:
> The mods are classes like
>
> class module(resource.Resource):
> def render_GET(self, request):
> # do something
>
> The reactor is started as:
> reactor.listenTCP(_port, server.Site(root))
> reactor.run( )
>
> Some of the GET request in the mods can take some time to complete. In the
> current situation other request to the server have to wait on this request.
>
> Is it possible to make soms kind of a thread/connection pool so that more
> then one request can be handled at the same time?
>
That wouldn't be very twisted :). Ideally your "# do something" code
could quickly return a deferred which would fire when the result is
ready. (I think it's a bit more complicated than just 'return
my_deferred', but not much.)
If the requests are spending time waiting for database requests, for
example, you could use a non-blocking deferred API to the database.
Worst case, if the delay is due to something that you really need to
multi-thread, you could use t.i.threads.deferToThread on just that
section. Then twisted would use a thread pool for the parts that need it
and connect the rest of your code into the deferred event style.
More information about the Twisted-web
mailing list