[mod_python] module caching problem

Nick nick at dd.revealed.net
Wed Dec 1 09:56:02 EST 2004


Running debian?  Boy, that sure is the hard way.  Try apt-get install 
apache2-mpm-worker.  If you're running woody, use backports.org.

Nick

Chris Curvey wrote:
> 1) build your apache server with mpm_worker (./configure 
> -with-mpm=worker)  (this only works with Apache 2.x)
> 
> 2) in httpd.conf  (all values of "150" in this example should be set to 
> the max number of concurrent requests)
> 
> ThreadLimit 150
> ServerLimit 1
> StartServers 1
> MaxClients 150
> MinSpareThreads 1
> MaxSpareThreads 150
> ThreadsPerChild 150
> MaxRequestsPerChild 0
> 
> I have not tested this a whole bunch, but it should work, according to 
> http://httpd.apache.org/docs-2.0/mod/worker.html
> 
> I'm also not sure of the knock-on effects on performance of doing this.  
> YMMV.  If anyone knows of a good reason *not* to do this, please speak up.
> 
> -Chris
> 
> P.S.  Even in prefork mode, if an apache process needs a module that has 
> already been loaded into memory *by that process*, it will be re-used 
> and not reloaded.
> 
> Huzaifa Tapal wrote:
> 
>> Yes I am using linux on a debian OS.  How can I configure apache to 
>> not run
>> with mpm_prefork?  Pretty much I want to use Shared Memory with 
>> mod_python
>> so that for simultaneous requests it uses any modules that are already
>> loaded in memory rather than instantiating new processes.
>>
>> Any ideas?
>>
>> Hozi 
>> -----Original Message-----
>> From: mod_python-bounces at modpython.org
>> [mailto:mod_python-bounces at modpython.org] On Behalf Of Damjan
>> Sent: Tuesday, November 23, 2004 6:49 PM
>> To: mod_python at modpython.org
>> Subject: Re: [mod_python] module caching problem
>>
>>  
>>
>>> I am running into a problem with mod_python in that, I am importing a
>>>   
>>
>> module
>>  
>>
>>> in the handler which creates a singleton in memory.  I am using the 
>>> module
>>> to hold cache information for any other modules that import the same
>>>   
>>
>> module.
>>  
>>
>>> I started testing the cache mechanism when I noticed that the module was
>>> being imported multiple times and not just once after the first request
>>> after apache had started.  To test this, I put a few lines of code in 
>>> the
>>> module to write to a file the time it was last imported.  I noticed that
>>> after restarting apache, the first time it writes to the file.  If I hit
>>> refresh on my page immediately, multiple times, it doesn't write.  If I
>>>   
>>
>> wait
>>  
>>
>>> like 10 seconds or more and then hit refresh again, it reimports that
>>>   
>>
>> module
>>  
>>
>>> that should have been cached.
>>>
>>> Also, If I make a request for a page from two different clients, it
>>> reimports the module from each client.  Am I mistaken in thinking 
>>> that any
>>> module imported in the handler then is cached in mod_python's module 
>>> cache
>>> and subsequent imports of that module then are simply served up from the
>>> cache.  Under what conditions then would the same module get 
>>> reimported if
>>> no modifications were made to that module?
>>>   
>>
>>
>> I guess your are runnig Apache with mpm_prefork? In that case there's 
>> a completely different python interpreter for each
>> Apache process, so your caching module is loaded in each of them.
>>
>> Your testing showed how apache processes get to serve requests, if it 
>> gets
>> two simultaneus requests two apache processes will be active, each
>> serving one of the request. But if you only generate one request after
>> another, its most likely that the same process will serve  both
>> requests... of course this depends on OS implementation... I think you
>> are running on Linux, no?
>>
>>  
>>
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python



More information about the Mod_python mailing list