Prefork-MPM not handing out simultaneous requests to separate

Prefork-MPM not handing out simultaneous requests to separate

am 31.01.2008 21:09:56 von urcabraz

I might be missing something, but the pre-fork MPM doesn't behave as
I'd expect when faced with multiple long-running requests. (Apache +
mod_perl2.)

I'm running prefork-MPM and see that HTTP requests apparently aren't
farmed out to worker 'httpd' processes like I'd expected.

I'm using the stock 'httpd' from Fedora 8, with 'httpd -V':

[root@fullhouse pg_log]# httpd -V
Server version: Apache/2.2.6 (Unix)
Server built: Sep 18 2007 03:54:41
Server's Module Magic Number: 20051115:5
Server loaded: APR 1.2.11, APR-Util 1.2.10
Compiled using: APR 1.2.11, APR-Util 1.2.10
Architecture: 32-bit
Server MPM: Prefork
threaded: no
forked: yes (variable process count)

Here is the prefork configuration in httpd.conf:


StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000


After starting 'httpd' I see these relevant httpd processes:

[telosdev@fullhouse thefifth_web]$ pstree -pn | grep httpd
|-httpd(2828)-+-httpd(2830)
| |-httpd(2831)
| |-httpd(2832)
| |-httpd(2833)
| |-httpd(2834)
| |-httpd(2835)
| |-httpd(2836)
| `-httpd(2837)



I have mod_perl2 and a 'startup.pl' that loads all expected mod_perl2/
Apache2 Perl modules. I have a handler defined like this:

sub handler {

my $r = shift;

# Print junk to begin
$r->content_type('text/plain');
print("this is content from the EgModule01.pm module\n\n");

# Sleep a little for testing
sleep(10); # <-------- the 'httpd' prefork
server as configured should be able to handle
# 2 requests with this handler
simultaneously in separate processes,
# even with this 10-second delay,
right?

# Are we done? Yes!
printf("\nDone at time %s for pid %s!\n", time(), getppid());

return Apache2::Const::OK;
}

Here's when I see the unexpected:

* I open two browser tabs so I can run two nearly simultaneous
fetches of the relevant test URL
* I submit first request in one browser tab
* After waiting two seconds I submit the same URL in the other tab
* I'd expect the two separate but identical URLs to run in
different worker 'httpd' processes, and finish nearly two seconds
apart (note the 10-second delay in the script)
* instead, both are run serially on the "parent" 'httpd' process,
and the second one finishes ten seconds after the first ... meaning
both requests were executed serially
* .... what's going on? I apparently don't understand the prefork
MPM thingy.


Here are the last two lines from each of the two URL fetches (that
were started only 2 seconds apart) ... they should same PID, the
parent 'httpd' process, handled both requests:

* Done at time 1201787367 for pid 2828!
* Done at time 1201787377 for pid 2828!


Please comment. Thanks for your time!

Re: Prefork-MPM not handing out simultaneous requests to separate processes

am 31.01.2008 21:31:38 von Jim Hayter

urcabraz@gmail.com wrote:
> I might be missing something, but the pre-fork MPM doesn't behave as
> I'd expect when faced with multiple long-running requests. (Apache +
> mod_perl2.)
>
[snip]
> Here's when I see the unexpected:
>
> * I open two browser tabs so I can run two nearly simultaneous
> fetches of the relevant test URL
> * I submit first request in one browser tab
> * After waiting two seconds I submit the same URL in the other tab
> * I'd expect the two separate but identical URLs to run in
> different worker 'httpd' processes, and finish nearly two seconds
> apart (note the 10-second delay in the script)
> * instead, both are run serially on the "parent" 'httpd' process,
> and the second one finishes ten seconds after the first ... meaning
> both requests were executed serially
> * .... what's going on? I apparently don't understand the prefork
> MPM thingy.
>
>
> Here are the last two lines from each of the two URL fetches (that
> were started only 2 seconds apart) ... they should same PID, the
> parent 'httpd' process, handled both requests:
>
> * Done at time 1201787367 for pid 2828!
> * Done at time 1201787377 for pid 2828!
>
>
> Please comment. Thanks for your time!

Instead of two tabs in one browser, what happens if you do one request
from FireFox and one from IE? The serialization may be an affect of the
browser, not of your apache config. Or it might be affected by the
KeepAlive timeout you have set in the apache config.

HTH,
Jim

Re: Prefork-MPM not handing out simultaneous requests to separate

am 31.01.2008 22:58:37 von urcabraz

> Instead of two tabs in one browser, what happens if you do one request
> from FireFox and one from IE? The serialization may be an affect of the
> browser, not of your apache config. Or it might be affected by the
> KeepAlive timeout you have set in the apache config.
>
> HTH,
> Jim

Jim,

Thank you very much for your response. I did the multi-browser thing
and sure enough, it worked. The two requests from the separate
browsers that were started about two seconds apart did return the page
at the same time, each after the 10-second delay. So 'httpd' is
passing off the requests to separate children.

I also saw I was mistakenly using 'getppid()' to print process ID OF-
THE-PARENT rather than the process itself. Using '$$' showed the
proper process ID (the child 'httpd' process). I also kept a file
open in the script in read-only mode and used 'lsof' to find which
processes had it opened ... again pointed to the child processes.
Latest results:

[root@fullhouse data]# lsof | grep THE_MARKER
httpd 7338 telosdev 1w REG 253,0 0
2357940 /home/telosdev/THE_MARKER.txt <-- from one browser
httpd 7339 telosdev 1w REG 253,0 0
2357940 /home/telosdev/THE_MARKER.txt <-- from other browser
[root@fullhouse data]# pstree -pn | grep 'httpd'
|-httpd(7336)-+-httpd(7338) <--- this child handles one
request
| |-httpd(7339) <--- this child handles
other request
| |-httpd(7340)
| |-httpd(7341)
| |-httpd(7342)
| |-httpd(7343)
| |-httpd(7344)
| `-httpd(7345)

The last line as returned by each browser page:

* Done at time 1201816544 for pid 7339!
* Done at time 1201816546 for pid 7338!

All is well.

Thanks again! I'm not a web developer, though I've done lots of
server programming. Much to learn yet.

Urca Braz