[mod_python] concurrent connections

Graham Dumpleton grahamd at dscpl.com.au
Mon Jul 24 19:33:24 EDT 2006

Jay Knight wrote ..
> If you take the hello world example, and add a time.sleep(5) at the
> beginning... like this:
> -----
> import time
> from mod_python import apache
> def handler(req):
>     time.sleep(5)
>     req.content_type = "text/plain"
>     req.write("Hello World!")
>     return apache.OK
> -----
> Then request that URL twice, it seems that the second one doesn't
> start until the first one is completely finished, that is, I can't
> make them run at the same time.  (And therefore, if I started 20 at
> about the same time, the last one would not complete until about 100
> seconds later, etc)  How would I go about making them run at the same
> time?
> I've got a pretty standard mod_python install on gentoo.  The
> .htaccess for this directory is
> -----
> AddHandler mod_python .py
> PythonHandler mptest
> PythonDebug On
> -----
> I know this must be possible.  But I don't know if it is a
> configuration issue (.htaccess) or something within the code itself
> (manually forking stuff off to handle multiple connections? bleh).

Apache should handle everything for you so as to allow concurrent

Some questions for you.

1. What client are you using to create the connections and test this?
Are you sure it isn't the client that is serialising the requests?

One would normally use 'ab" to do such a test. For example:

  ab -n 10 -c 5 http://localhost/some/path

The '-n' option says 10 requests, with '-c' saying run 5 concurrently.

2. What version of Apache are you using?

3. If Apache 2.X, what MPM is compiled in to it, worker or prefork?

You can determine this by going:

  httpd -l

and then looking for either 'worker.c' or 'prefork.c' file being compiled in.

4. How is Apache configured in respect of number of child processes
to create etc.

For example:

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0


<IfModule mpm_worker_module>
    StartServers          2
    MaxClients          150
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadsPerChild      25
    MaxRequestsPerChild   0

5. What version of mod_python are you using?


More information about the Mod_python mailing list