[mod_python] mod_python executing old versions of my code

Jim Gallacher jpg at jgassociates.ca
Thu Jan 26 19:36:07 EST 2006

Peter Sanchez wrote:
> I have been a little slow on this thread. This is something I had  
> planned on emailing the list about myself.
> I have a page hosted using mod_python.publisher (mod_python version  
> 3.2.5b) The page returns results from a PSP formatted template  system. 
> On a lot of pages I use a variable named "info_msg"
> Say I login to an account, info_msg is set to 'You have logged in.'  Go 
> to a new page, info_msg isn't used, but the template page does  
> reference it (in case it was used) and you see 'You have logged in' I  
> have been trying to figure it out, but no such luck. I just found  this 
> thread :)

 From what you are describing here I don't think this is a module reload 
problem. How are you passing info_msg between your requests? In the 
apache preform-mpm and worker-mpm models there will be a python 
interpreter for each apache child process. Each interpeter gets it's own 
copy of the module data. The value for a module variable set in a 
request in one child will only be visible to subsequent requests handled 
by that same child. If you want to share some data between different 
requests you'll need to use sessions, cookies, dump it into a database, 
or some other persistent store.

> As for the "MaxRequestsPerChild 1" work around. How big of a  
> performance hit does this give? Seems like it would slow things down  a 
> bit. 

Wrong. It'll slow it down *alot*. This trick should really only be used 
on a development machine. Consider the following results for a random 
bit of mod_python code on my machine.

Using ab -n 1000 and the following apache config:
StartServers         5
MinSpareServers      5
MaxSpareServers      10
MaxClients          50

For MaxRequestsPerChild 0
Concurrency Level:      1
Time taken for tests:   4.593905 seconds
Complete requests:      1000
Requests per second:    217.68 [#/sec] (mean)
Time per request:       4.594 [ms] (mean)
Transfer rate:          1061.84 [Kbytes/sec] received

For MaxRequestsPerChild 1
Concurrency Level:      1
Time taken for tests:   378.930349 seconds
Complete requests:      1000
Requests per second:    2.64 [#/sec] (mean)
Time per request:       378.930 [ms] (mean)
Transfer rate:          12.87 [Kbytes/sec] received

Ouch. Performance drops by a factor of 100 for MaxRequestsPerChild == 1. 
You could set StartServers to compensate, but it's not a general solution.

> When will 3.2.6 be available?

Unofficially, now. ;) Officially... well, we are likely going to have 
that discussion on the python-dev list in the next day or so.


More information about the Mod_python mailing list