You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Tim Dunphy <bl...@gmail.com> on 2015/11/03 16:43:23 UTC

[users@httpd] prefork vs worker mpm in apache

Hey guys,

We had to recompile apache 2.4.12 because we needed to disable thread
safety in php (ZTS).  Because for some reason when compiling php with the
--disable-maintainer-zts with the worker mpm model and checking the php
info page, it was saying that thread safety was still enabled.

So when we recompiled apache to use the prefetch worker model instead of
worker, the php info page was showing that  thread safety was disabled.

But after that change apache processes spiked from around 11 processes per
machine to well over 250 processes at any given time.

These are the tuning settings we have in apache:

StartServers 10

#MinSpareServers 10

#MaxSpareServers 25

ServerLimit 250

MaxRequestWorkers 250

MaxConnectionsPerChild 1000

KeepAlive On

KeepAliveTimeout 30

EnableSendfile Off


So I was just wondering how this change could've cause this problem of
having the number of apache processes spike. And if there are any other
changes we can make to apache to bring the process count down?

Also I realize that installing apache / php from source isn't standard
practice on red hat variants. But at the time that these servers were setup
the latest apache at that time (2.4.12) wasn't available as an RPM. So we
just decided to install from source.

Thanks
-- 
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B

Re: [users@httpd] prefork vs worker mpm in apache

Posted by Tom Evans <te...@googlemail.com>.
On Tue, Nov 3, 2015 at 3:43 PM, Tim Dunphy <bl...@gmail.com> wrote:
>
> Hey guys,
>
> We had to recompile apache 2.4.12 because we needed to disable thread safety
> in php (ZTS).  Because for some reason when compiling php with the
> --disable-maintainer-zts with the worker mpm model and checking the php info
> page, it was saying that thread safety was still enabled.

This is unsurprising. If you use a threaded process manager in apache,
you will need thread safety in anything embedded in to apache.

>
> So when we recompiled apache to use the prefetch worker model instead of
> worker, the php info page was showing that  thread safety was disabled.
>
> But after that change apache processes spiked from around 11 processes per
> machine to well over 250 processes at any given time.


*Prefork* will fork one process for each concurrent request you
handle. So if you have ServerLimit 250, and 250 concurrent requests,
you will need enough RAM/CPU to handle 250 processes.

This is why it prefork is avoided, it is very expensive for high volume sites.

>
> These are the tuning settings we have in apache:
>
> StartServers 10
>
> #MinSpareServers 10
>
> #MaxSpareServers 25
>
> ServerLimit 250
>
> MaxRequestWorkers 250
>
> MaxConnectionsPerChild 1000
>
> KeepAlive On
>
> KeepAliveTimeout 30
>
> EnableSendfile Off
>
>
> So I was just wondering how this change could've cause this problem of
> having the number of apache processes spike. And if there are any other
> changes we can make to apache to bring the process count down?

This is all explained in the docs for each of those directives. With
prefork, to handle 250 clients will require 250 processes. With
worker, it will start 25 worker threads per process (ThreadsPerChild),
so to handle 250 clients requires only 10 processes.

I would recommend to detach PHP from Apache, and run them
independently, using fastcgi and PHP-FPM.

Cheers

Tom

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] prefork vs worker mpm in apache

Posted by Jim Jagielski <ji...@jaguNET.com>.
> On Nov 3, 2015, at 2:53 PM, Rose, John B <jb...@utk.edu> wrote:
> 
> On 11/3/15 2:21 PM, "Jim Jagielski" <ji...@jaguNET.com> wrote:
> 
>> 
>>> On Nov 3, 2015, at 10:43 AM, Tim Dunphy <bl...@gmail.com> wrote:
>>> 
>>> 
>>> Hey guys,
>>> 
>>> We had to recompile apache 2.4.12 because we needed to disable thread
>>> safety in php (ZTS).  Because for some reason when compiling php with
>>> the --disable-maintainer-zts with the worker mpm model and checking the
>>> php info page, it was saying that thread safety was still enabled.
>>> 
>>> So when we recompiled apache to use the prefetch worker model instead
>>> of worker, the php info page was showing that  thread safety was
>>> disabled.
>>> 
>>> But after that change apache processes spiked from around 11 processes
>>> per machine to well over 250 processes at any given time.
>>> 
> 
> Does "Prefetch worker" = Event MPM? I thought "Event" with PHP-FPM was the
> suggested config.

There are 3 standard MPMs: Prefork (which is the old 1.3 way),
Worker and Event. Event is the recommended for 2.4.x

> 
>>> These are the tuning settings we have in apache:
>>> 
>>> StartServers 10
>>> 
>>> #MinSpareServers 10
>>> 
>>> #MaxSpareServers 25
>>> 
>>> ServerLimit 250
>>> 
>>> MaxRequestWorkers 250
>>> 
>>> MaxConnectionsPerChild 1000
>> 
>> Should be 0.
> 
> What "Should be 0"?

What MaxConnectionsPerChild does it to kill off a child
process after it handles 1000 connections. For even moderately
used servers, this causes nasty thrashing as the parent httpd
process is constantly killing off and then recreating perfectly
fine child processes. This directive was originally add long
long ago when there were memory leaks in libs and so you
needed Apache httpd to occasionally kill child processes to
recover that mem.

> 
> 
>> 
>>> 
>>> KeepAlive On
>>> 
>>> KeepAliveTimeout 30
> 
> Seems like I have read in somewhat recent exchanges that "KeepAlive Off"
> is the recognized preference?
> 

That's also fine. It really depends on one's environment and
usage pattern if keepalives makes sense or not.

>> 
>> Should be 3 or so
>> 
>>> 
>>> EnableSendfile Off
>> 
>> Should be On
>> 
>> 
>> Cheers!
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
> 
> 
> Thanks
> 
> 
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] prefork vs worker mpm in apache

Posted by "Rose, John B" <jb...@utk.edu>.
On 11/3/15 2:21 PM, "Jim Jagielski" <ji...@jaguNET.com> wrote:

>
>> On Nov 3, 2015, at 10:43 AM, Tim Dunphy <bl...@gmail.com> wrote:
>> 
>> 
>> Hey guys,
>> 
>> We had to recompile apache 2.4.12 because we needed to disable thread
>>safety in php (ZTS).  Because for some reason when compiling php with
>>the --disable-maintainer-zts with the worker mpm model and checking the
>>php info page, it was saying that thread safety was still enabled.
>> 
>> So when we recompiled apache to use the prefetch worker model instead
>>of worker, the php info page was showing that  thread safety was
>>disabled.
>> 
>> But after that change apache processes spiked from around 11 processes
>>per machine to well over 250 processes at any given time.
>> 

Does "Prefetch worker" = Event MPM? I thought "Event" with PHP-FPM was the
suggested config.

>> These are the tuning settings we have in apache:
>> 
>> StartServers 10
>> 
>> #MinSpareServers 10
>> 
>> #MaxSpareServers 25
>> 
>> ServerLimit 250
>> 
>> MaxRequestWorkers 250
>> 
>> MaxConnectionsPerChild 1000
>
>Should be 0.

What "Should be 0"?


>
>> 
>> KeepAlive On
>> 
>> KeepAliveTimeout 30

Seems like I have read in somewhat recent exchanges that "KeepAlive Off"
is the recognized preference?

>
>Should be 3 or so
>
>> 
>> EnableSendfile Off
>
>Should be On
>
>
>Cheers!
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>For additional commands, e-mail: users-help@httpd.apache.org


Thanks


>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] prefork vs worker mpm in apache

Posted by Jim Jagielski <ji...@jaguNET.com>.
> On Nov 3, 2015, at 10:43 AM, Tim Dunphy <bl...@gmail.com> wrote:
> 
> 
> Hey guys,
> 
> We had to recompile apache 2.4.12 because we needed to disable thread safety in php (ZTS).  Because for some reason when compiling php with the --disable-maintainer-zts with the worker mpm model and checking the php info page, it was saying that thread safety was still enabled.
> 
> So when we recompiled apache to use the prefetch worker model instead of worker, the php info page was showing that  thread safety was disabled.
> 
> But after that change apache processes spiked from around 11 processes per machine to well over 250 processes at any given time.
> 
> These are the tuning settings we have in apache:
> 
> StartServers 10
> 
> #MinSpareServers 10
> 
> #MaxSpareServers 25
> 
> ServerLimit 250
> 
> MaxRequestWorkers 250
> 
> MaxConnectionsPerChild 1000

Should be 0.

> 
> KeepAlive On
> 
> KeepAliveTimeout 30

Should be 3 or so

> 
> EnableSendfile Off

Should be On


Cheers!
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org