Re: [Hampshire] Apache performance tuning.

Top Page

Reply to this message
Author: Graham Bleach
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] Apache performance tuning.
2009/1/7 David Ramsden <david@???>:
> 1) Use Apache's prefork MPM:
> The site uses PHP which isn't considered thread safe, so I'm loathed to
> use the worker MPM. I did consider using the worker MPM with
> fastcgi/fcgid but again, I read stories of lots of defunct processes
> appearing.


There are reports of success using PHP on the worker MPM; I think it's
application dependent. One to keep as a last resort.

> 2) Remove any un-needed Apache modules to reduce the memory footprint.


Probably won't help much, but won't do any harm and won't take long.

> 3) Use mod_deflate to reduce bandwidth (trade off is server load?).


I wouldn't go anywhere near mod_deflate until you have the load issues
on the server under control.

> And then in terms of tuning (based on using the prefork MPM):
>
> 1) Calculate MaxClients based on:
> (Physical RAM - RAM in use by other processes) / Average Apache process size
> I've actually written a (hacky) shell script to do this for me. You can
> see it here: http://0wned.it/temp/calcmaxclients.sh.txt


The empirical way is to progressively increase StartServers,
restarting apache each time until the server starts to run out of
memory. Knock 10-20 off this number and you have the maximum number of
apache processes your machine can support.

> 2) KeepAlive On but set the KeepAliveTimeout to a low value, so that a
> client doesn't use a process for massive amount of time.


Agreed, I usually favour 3-5 seconds for sites which are trying to
optimise for multiple HTTP requests per page.

> 3) Lower the Timeout value.


Won't help performance much, but will help the site recover more
quickly when things start to go wrong.

> 4) Calculate MaxRequestsPerChild based on:
> (Requests per 24 hours / Apache processes) which will hopefully mean
> processes don't linger for more than 24 hours.


If you want to ensure all processes get restarted every 24 hours, then
cron a graceful restart. This is what logrotate does anyway on Debian
based systems. The important thing about MaxRequestsPerChild is not to
set it too low, as this will just cause excessive fork()s under load.
It should tens or hundreds of thousands unless you have some truly
horrifyingly leaky modules or libraries.

> I'm also looking in to implementing a PHP caching system like APC.
>
> So if anyone agrees or disagrees with the above, has any tips, hints or
> experiences with Apache performance tuning for sites that receive lots
> of hits, I'd be grateful to hear from you :)


+1 for Vic's suggestion of more RAM.

You seem to be focussing on apache tuning. How much memory is mysqld
using and does it increase under load?

G