Running a bunch of PHP sites via apache2.4/mod_php on RHEL using the prefork MPM.

My apache children are using a fair bit of RAM and lots of CPU.

I would like to be able to attribute RAM/CPU use on a per-virtual-host basis.

One idea I had was to use PHP-FPM and create one worker pool per virtual host. However, not clear to me if I can name or tag the worker processes so that I can aggregate resource-use stats in a meaningful way.

I feel like big shared hosts must have faced this problem before.

Any ideas?


With prefork mod_php you are more or less clueless about RAM/CPU usage of different vhosts. Problem is that all apache processes run under same user, and every process serves all vhosts. So one process can serve vhostA in one moment and vhostB in other.

To make the matter worse, with each request served, for apache processes with mod_php RAM usage tends to grow until process serves MaxRequestPerChild requests, after which process retires, and new, small and lean process takes its place. So it's virtually impossible to track usage of resources with prefork/mod_php.

What you can do is utilize a tool that parses access_log, like apachetop, and watch the kind of requests apache serves. That won't give you very grained results, but you'll at least see some kind of patterns. That may help you if one of your vhosts is thrashing whole server.

On the other hand, if you want better solution, there are couple of way you can pursuit this problem. You could swap prefork for itk. mpm-itk allows you to run each vhost under different UID/GID - which will in turn solve your problem of resource consumption metrics - you could simply monitor per-UID RAM usage for example.

Other direction is PHP-FPM with separate pool for each vhost. But that will only separate PHP resource consumption, you still won't be able to see what apache does. But, with removal of mod_php from apache processes, you can run them with mpm-worker (threaded model) and RAM usage of apache would probably be negligible in comparison to PHP. Regarding process tagging - you can simply run them under different UID.

  • Is there a way that I can run all apache processes as the same UID/GID and still aggregate useful stats on resource consumption? Maybe FPM or ITK provide a way to specify the command line name or program name (as seen in ps, top, pstree), etc. I am using New Relic, so an approach that works easily with that monitoring and reporting system is best. – astletron Nov 25 '14 at 11:29
  • If aggregation by UID/GID is the only way, what is the best tool for studying resource use aggregated in this way? – astletron Nov 25 '14 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.