[mod_python] concurrent connections

Jay Knight jhknight at gmail.com
Mon Jul 24 23:18:57 EDT 2006


1.  I was just using firefox when I noticed this behavior.
2. 2.0.58
3. looks like it's prefork
4. StartServers            2
    MinSpareServers         1
    MaxSpareServers         5
    MaxClients             64
    MaxRequestsPerChild  4000
5. 3.1.4

I just now noticed that this behavior only happens when the same URL
is called.  For example, if I have a file test.py in this directory,
and call its url, the mptest.py is still used because it's defined as
the handler.  If I try to load mptest.py and test.py at the same time,
they will both return 5 seconds later, but calling the same URL twice
will invoke the problem.

Everything else running on this server has no trouble with
concurrancy, just these scripts, so I'm guessing it's not apache
itself.

Any more ideas?

Jay K

On 7/24/06, Graham Dumpleton <grahamd at dscpl.com.au> wrote:
> 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
> connections.
>
> 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>
>
> or:
>
> <IfModule mpm_worker_module>
>     StartServers          2
>     MaxClients          150
>     MinSpareThreads      25
>     MaxSpareThreads      75
>     ThreadsPerChild      25
>     MaxRequestsPerChild   0
> </IfModule>
>
> 5. What version of mod_python are you using?
>
> Graham
>


More information about the Mod_python mailing list