Re: [Twisted-Python] connection pool

I have build a webserver with Twisted 2.4 with imports of the following:
from twisted.web import resource, static, server, twcgi from twisted.internet import reactor
I'm adding several mods as child to the root with:
root = static.File(settings.getSetting("html_directory")) root.putChild(mods.getPath(), mods
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?
Regards, Tjerk
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Yes it is possible to use a thread pool, in fact twisted comes with one. However, how you use it depends on what is taking so long for you:
- if it's database calls then consider using twisted.enterprise.adbapi - http://twistedmatrix.com/projects/core/documentation/howto/enterprise.html
- if it's python code taking so long then consider breaking your code into shorter snippets that yield control back to twisted periodically so that other requests don't get ignored
- if it's network code then make sure you're using Deferred's properly - http://twistedmatrix.com/projects/core/documentation/howto/defer.html
The call can take some time because I have to wait on a response from a CORBA call. I have looked at deferred's, but can not see how this can be used to solve the problem. The render_GET(self, request) can only return when there is an answer. Is there a way to make twisted web to handle multi connections at the same time? Regards, Tjerk

Quoting Tjerk.Kusters@imtech.nl:
The call can take some time because I have to wait on a response from a CORBA call.
I have looked at deferred's, but can not see how this can be used to solve the problem. The render_GET(self, request) can only return when there is an answer.
Is there a way to make twisted web to handle multi connections at the same time?
You're misunderstanding something. twisted.web can handle multiple connections without problems. I think your problem is that you're making a blocking call (CORBA) inside the reactor loop, which prevents other connections to happen. If you don't manage to find an asynchronous CORBA client, you should do the call inside a thread, using reactor.callInThread for example. However, it would be easier to help you with an example of your code or a more detailed description of your problem. -- Thomas
participants (2)
-
Thomas Hervé
-
Tjerk.Kusters@imtech.nl