[medusa] Multi-threaded web-server design issues
Sam Rushing
rushing@n...
Tue, 31 Jul 2001 01:44:46 -0700
---------------------- multipart/alternative attachment
"John E. Barham" wrote:
> 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?
The purpose of the trigger is to provide a way to 'wake up' the
select() call that is pending in the main asyncore event loop. Even if
you had a separate thread that pulled out of a central queue, you'd
still need to address this issue...
> Also, from what I can see from the code, the only http_request method
> that isn't thread-safe is done(). Is this correct? That would mean
> that each CGI thread
> could safely manipulate the request object itself, leaving the
> response-handling queue to (serially) invoke done().
As long as you processed the requests carefully - for example, let's say
that you were sent three pipelined requests on an http/1.1 channel. If
you're not careful, the requests might get retired out-of-order, and
thus push the responses out of order. If you disable http/1.1 (or just
pipelining) then it's probably not an issue.
-Sam
---------------------- multipart/alternative attachment
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail-21/medusa-dev/attachments/812f7f4b/attachment.html
---------------------- multipart/alternative attachment--