[mod_python] Mod_python and Sub-Interpreter segregation

Brian Hawthorne brianh at exelixis.com
Fri Sep 13 14:58:33 EST 2002


hmmm,
currently you can share global vars if you set apache to have exactly one
child process (but to great performance detriment).  i was imagining you
could do the same in the perthread server by setting the numprocs=1 and
letting the numthreads grow/shrink (recouping the performace hit with
extra threads).

actually, it should be pretty easy to wrap a bit of code around python
shelve to turn some dbm file into a modpyglobal repository of python objs
keyed by varname.  that's what i would do if i didn't feel like dealing
with a real db.  also, if you don't use an external repository, you have
to worry about server restarts and child procs getting killed etc.

brian


On Fri, 13 Sep 2002, Michael C. Neel wrote:

> I don't think this will work in apache2 either, based on my limited
> experience.
> 
> Apache2 threaded still has separate processes (children) along with
> threads.  You can either have a fixed number of processes, and let the
> threads grow and shrink, or have a fixed number of threads per process
> and add more processes as needed.
> 
> While this will help with resource pooling, you'll still need an outside
> database to have a global variable.  Now with apache2's cgid (a process
> to handle all cgi scripts since forking a 75 thread apache child would
> be, um, bad) there might be something you can do there, but then that
> means you app is a CGI and we don't use that word in 2002 anymore...
> 
> Mike 
> 
> --
> Michael C. Neel
> There are only 10 types of people in the world;
> those who understand binary and those who don't.
> 
> 
> -----Original Message-----
> From: Brian Hawthorne [mailto:brianh at exelixis.com] 
> Sent: Friday, September 13, 2002 5:29 PM
> To: Bryan Mongeau
> Cc: mod_python at modpython.org
> Subject: Re: [mod_python] Mod_python and Sub-Interpreter segregation
> 
> 
> unfortunately, there is no way to share global data among multiple
> apache child processes without using an external database of some sort.
> this is true regardless of how many interpreters you have in each child
> proc.  i anticipate that the multithreaded server model available in
> apache2 will address this issue, though i haven't gotten my hands dirty
> yet trying to set up modpy3 alpha with apache2.
> 
> brian hawthorne
> -bioinformatics,
> Exelixis, Inc.
> 
> 
> On Fri, 13 Sep 2002, Bryan Mongeau wrote:
> 
> > Greetings,
> > 
> > I've been playing around with mod_python and have noticed a peculiar
> behaviour 
> > that perhaps someone could explain to me.  As the mod_python
> documentation 
> > explains, a sub-interpreter is created for each virtual host
> (default).  I 
> > therefore expected global variables within this sub-interpreter to be
> able to 
> > maintain state between hits.  I created a simple script ( included
> below ) to 
> > observe this behaviour by counting hits in a global variable and
> printing the 
> > interpreter name.
> > 
> > To my surprise, it seems as if different apache child processes run
> their 
> > python code in different sub-interpreters even though the interpreter
> name 
> > remains the same ( virtualhost ). I produced this behaviour by loading
> the 
> > script in my browser and refreshing (very) rapidly. What happens is
> the hit 
> > counter eventually returns to zero, meaning that the global variable
> is no 
> > longer in the namespace. Repeated refreshing causes the hit counter to
> jump 
> > all over the place as I presume it jumps from one apache child process
> to 
> > another, each having their own sub-interpreters and global variables.
> > 
> > It seems as if each child process has its own sub-interpreter? Or am I
> 
> > confused? Was this documented? Enlightenment is greatly appreciated. 
> > Unfortunately the behaviour I am observing is undesired.
> > 
> > Here is the code to demonstrate:
> > 
> > from mod_python import apache
> > def handler(req):
> >     try:
> >         globals()['hits']+=1
> >     except KeyError:
> >         globals()['hits'] = 0
> >     req.write("interpreter_name=" + req.interpreter )
> >     req.write(" - hits: " + str(globals()['hits']))
> >     return apache.OK
> > -- 
> > Bryan Mongeau
> > eEvolved Inc. - IT Consulting & Custom Software
> > http://eevolved.com/
> > --
> > "The true function of life, that which is being maximized in the
> natural 
> > world, is DNA survival. But DNA is not floating free; it is locked up
> in 
> > living bodies and it has made the most of the levers of power at its 
> > disposal." -- Richard Dawkins
> > 
> > _______________________________________________
> > Mod_python mailing list
> > Mod_python at modpython.org
> > http://www.modpython.org/mailman/listinfo/mod_python
> > 
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://www.modpython.org/mailman/listinfo/mod_python
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://www.modpython.org/mailman/listinfo/mod_python
> 




More information about the Mod_python mailing list