Re: RAM problem with apache and PHP on default centos configuration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On 12/12/2011 03:17 AM, Enrico Daga wrote:
> Hi all,
> 
> I send this mail to both httpd and php lists.
> I experienced the following problem running php scripts on httpd.
> The RAM fills gradually until the system starts swapping, then, if I
> don't restart the server, swap fills and everything goes down.
> After some try/check tests, I realized that the memory used by a
> single request is never released when the process is complete. This
> makes the RAM to be gradually filled.
> I thought in the beginning was a problem with the php application and
> circular references on objects (I found some posts about this) then I
> tried with a simple script (just populating a single array) but the
> problem still occurs.
> Our production environments are on Centos 4.9 - we have some legacy
> applications that prevented us to upgrade the servers before.
> For this sake I tried on fresh systems and more recent versions, and
> experienced the same problem on Centos 4.9, 5.5 / PHP 5.1.6 and Centos
> 6 / PHP 5.3.6, with distributed packages for both httpd and php and
> default configuration. Httpd uses the Prefork MPM module.
> I also noticed that this _do not_ happen on Ubuntu 11.10 server. I had
> a look at the configuration of both httpd and php, but in both cases
> (Centos and Ubuntu) I could not noticed a difference on parameters
> regarding memory usage.
> 
> Since this is the first time we run PHP applications on our httpd
> servers I guess there is some configuration I should modify to have
> the system behave correctly (free the memory when it is not needed).
> The only workaround would be to move the MaxRequestsPerChild parameter
> to 1, then killing the sub-process that hold the request, but I don't
> believe this is the right solution.
> Finally, I am not so sure that the issue I describe here belong to the
> httpd or php lists, in this case please apologies, I would be very
> happy if you can point me to a red-hat list (found a lot of lists, but
> no sure which is related to httpd/php issues).
> 
> Thank you very much for any hint.

What you are probably seeing is simply that you are running too many
httpd children and the cumulative memory usage is causing your problems.
In UNIX, processes do not free memory back to the operating system until
they exit. So each httpd process will hold onto whatever memory it has
allocated. What does happen though is that after each request the memory
used by that request is freed within the process so the next request
will reuse the same memory. What this means for you is that whatever
request uses the most memory is the amount of memory each httpd process
will eventually need. You can set a max memory limit in your config to
prevent requests from using too much memory.

There is no difference between Centos on Ubuntu here. You probably
simply ran different code on the two systems. Whatever you ran on your
Centos servers used more memory than what you ran on Ubuntu.

One way to monitor how much memory each script is using is to add
%{mod_php_memory_usage}n to your Apache LogFormat which will cause the
peak memory usage for each request to be logged in your access log file.

-Rasmus



[Index of Archives]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [Postgresql]     [PHP Books]     [PHP Databases]     [PHP SOAP]
  Powered by Linux