[mod_python] Lifecycle of mod_python instances

Jørgen Frøjk Kjærsgaard jfk at metation.com
Fri Nov 1 09:20:16 EST 2002


On Thu, 31 Oct 2002 17:04:30 -0500, Antonio L Rodriguez wrote
> Forgive me if this is more of an apache process question, but I 
> couldn't find it covered clearly in the docs.
> 
> When apache boots up (on *NIX) its starts a bunch of children 
> processes. Does each child have its own separate image of mod_python 
> execution space that is totally separate from the other images?

Correct. Apache 1.3 starts a process per simultaneous request it can handle.
Apache 2.0 is capable of running in threaded mode where the threads share
memory and thus can have global shared variables. I have no experience with
2.0 so far, though. See the documentation for Apache, in particular
http://httpd.apache.org/docs/mod/core.html#maxclients for 1.3 and
http://httpd.apache.org/docs-2.0/mod/mpm_common.html#maxclients for 2.0.

> That is, if I define a global var to measure hit counts in a script 
> and then I see this var dance up and down as each of the child 
> processes handles the request, do I infer correctly that there are 
> separate python interpreters living inside of each child process?

Exactly. You never know which process the next request will hit.

> If this is so, I'd be curious how people do global data structures 
> in this model, i.e. a database connection pool.

Truely global data with Apache 1.3 requires some kind of shared memory, which
isn't supported by mod_python. I use one database connection per child. This
works well, but of cause, if you configure your Apache to run with a lot of
idle children, you'll have a lot of idle connections. If your database system
has a limit as to how many simultaneous connections it can handle, be sure you
don't hit that limit. Raise it or limit the number of Apache processes.

/jfk

--
Jørgen Frøjk Kjærsgaard
Metation ApS - the system integrators
Kystvejen 29 - DK 8000 Århus C - www.metation.com



More information about the Mod_python mailing list