You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Greg Weiss <gr...@yahoo.com> on 2002/05/08 01:02:48 UTC

How does Apache/mod_perl hand off requests to apache child processes?

I have a sort of high-level question about how
Apache/mod_perl (Apache::Registry) internally works. 
I didn't find it directly addressed in the various
bits of documentation I've perused on a couple
occassions searching for an answer.

My question is basically this:  How does
Apache/mod_perl decide which idle Apache child process
to hand off a HTTP request to?  

Assuming an idle server, with a small to moderate
number of child processes holding different cached and
compiled Apache::Registry scripts based on past
requests, does Apache/mod_perl keep track of which
child process holds which script and direct an
incoming request to an idle apache child process with
that script cached?  Or does the incoming request
pretty much get distributed to a random idle apache
child process?  

My guess and modest experimentation indicate that it's
random and Apache doesn't attempt any such intelligent
handling, but I've been hoping to find out otherwise.
With 5 scripts and 10 apache child processes for
example, if past behavior is evenly distributed among
the scripts, the odds than an incoming request
triggers a recompile of a perl script would be 80%
then by my calculations, given each apache child
process only has one script compiled and cached at a
time.  Can someone cross-check me and confirm/deny or
explain?

Cheers, 
  GregW

__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

Re: How does Apache/mod_perl hand off requests to apache child processes?

Posted by Perrin Harkins <pe...@elem.com>.
> My guess and modest experimentation indicate that it's
> random and Apache doesn't attempt any such intelligent
> handling

That's correct, although I believe this was going to be changed in
mod_perl 2 so that at least when using threads there would be an attempt
to send requests to the most recently used free interpreter.  (Can
anyone confirm or deny if this made it in?)

> With 5 scripts and 10 apache child processes for
> example, if past behavior is evenly distributed among
> the scripts, the odds than an incoming request
> triggers a recompile of a perl script would be 80%
> then by my calculations, given each apache child
> process only has one script compiled and cached at a
> time.

That's not correct.  Each Apache process has an entire mod_perl
interpreter which can cache millions of scripts up to the limit of your
available memory.  What will normally happen is that after a brief
period all children will have all scripts cached.  You can improve on
this more by pre-loading things during startup, and by ensuring your
processes live as long as possible through correct use of
Apache::SizeLimit or Apache::GTopLimit.

- Perrin


Re: How does Apache/mod_perl hand off requests to apache child processes?

Posted by Paul Lindner <li...@inuus.com>.
On Tue, May 07, 2002 at 04:02:48PM -0700, Greg Weiss wrote:
> 
> My question is basically this:  How does
> Apache/mod_perl decide which idle Apache child process
> to hand off a HTTP request to?  

On Unix all apache children listen for connections on the socket.  The
kernel then picks one child process to handle the request and removes
the request from the TCP connection queue.

> My guess and modest experimentation indicate that it's
> random and Apache doesn't attempt any such intelligent
> handling, but I've been hoping to find out otherwise.
> With 5 scripts and 10 apache child processes for
> example, if past behavior is evenly distributed among
> the scripts, the odds than an incoming request
> triggers a recompile of a perl script would be 80%
> then by my calculations, given each apache child
> process only has one script compiled and cached at a
> time.  Can someone cross-check me and confirm/deny or
> explain?

This is true.  This is why we have things like Apache::RegistryLoader.
To get the optimum speed increase and memory savings you should
pre-load the most frequently used registry scripts in the parent
server process.  This allows for some memory to be shared across all
the apache child processes; and eliminates redundant loading of the
same unchanged script.

Both the Cookbook and the Guide describe how to achieve these
benefits...

-- 
Paul Lindner    lindner@inuus.com   ||||| | | | |  |  |  |   |   |

    mod_perl Developer's Cookbook   http://www.modperlcookbook.org/
         Human Rights Declaration   http://www.unhchr.ch/udhr/