[medusa] Multi-threaded web-server design issues

Donovan Baarda abo@m...
Wed, 01 Aug 2001 10:26:32 +1000 (EST)

Quoting "John E. Barham" <jbarham@o...>:

> Hi all,
> I'm trying to build a multi-threaded Web-server using Medusa's
> http_server.
> (I need threads because our Web app. has some long-lived CGI scripts w/
> heavy database access.) I based the initial design on the example HTTP
> server from the thread_handler.py code in the thread dir. of the Medusa
> distro. However, that code obviously hasn't been touched in a while (I
> had
> to change it to use the "new" http_request.split_uri(), used the
> standard
> Queue module etc. etc.) so am wondering if there's a better approach. 
> In
> particular, to simplify things, I'm thinking about creating a separate
> output queue (instead of the select_trigger stuff which has been giving
> me
> weird errors) where all of the CGI worker threads would put their output
> when they were finished. A separate response handling thread would then
> pull the responses off this queue and feed them back to Medusa. Is this
> a
> good approach?

You could have a look at ZServer that comes with Zope. This branched from 
medusa some time ago. It uses threads to get around the delays associated with 
fetching objects from remote databases. It uses quite a few nice tricks that 
you can use in medusa (callback producers etc).

Another alternative is to use my patch that allows producers to block using a 
ready() method. This way you can embed the cgi thread into a producer that you 
can push strait onto medusa. If you want this, let me know. I'm yet to 
integrate my patch with the latest release of medusa, and a show of interest 
will encorage me to get around to it.

ABO: finger abo@m... for more information.