Apache process races away (process size explosion)

I come here because I have searched and tried different optimization without finding any answers.

We have a server with four websites hosted. The frequentation is not very high (we are sure that the problem is not the number of visitors).

We have a LAMP architecture (Centos 6.4, Apache, MySQL and PHP in the latest version). We also use eaccelerator. On a recent server 16GB DDR3, Intel Xeon E3 (4 cores @3.1 GHz).

Apache has a basic configuration with a few modules disabled and few to try to resolve our problem. MaxClients = 150 and MaxRequestsPerChild = 100.

Our problem is that some apache process inflates on weight up to several GB (I have seen one at 12GB !!! it was launched since15 minutes). At most processes live a long time more they grow with a large CPU usage… Then monitoring restart Apache…

I had no idea where the problem can come. The Apache log show nothing abnormal. This problem occurs both during the day than at night and it seems random.

thank you for your help.

Answer

Several runtimes can run as apache in-process plugins, mod_php being the most common one.

In that case, any memory used by PHP is allocated by apache. As a rule, once the process grows to a given size, it will not shrink. After the PHP script is done executing, the Apache process which contained it can still keep the memory allocated. Assuming the next PHP page request hits a different apache process, you may find apache holding much more memory than is necessary.

The first place I’d look is the maximum allowable memory size for PHP, bearing in mind that the value can be changed at run-time by the PHP script. There’s a limit for a reason; set the limit to something reasonable bearing in mind that the total memory consumption will be the number of running processes multiplied by the per-process limit.

A workable long-term solution is to take PHP out of the Apache process; run under fastCGI using mod_fcgid, for example. This allows you to specify a limit on the number of PHP processes which is lower than the number of apache processes. Since apache is used to serve more than just PHP, and therefore probably requires more processes than PHP, separating the two out allows you to make more efficient use of your resources at hand.

Attribution
Source : Link , Question Author : Florian , Answer Author : tylerl

Leave a Comment