In many cases. Apache will leak memory. Because of memory leak, Apache will not be able to fork new child processes to serve new requests. However httpd still can answer requests with pre-allocated memory.
To solve this memory leak in Apache, usually we need to restart Apache service to free up memory. In case of frequent memory leaks, to restart the Apache
- We can set a cron job to restart apache every "n" hours Or
- If logrotation is in place for Apache, during logrotation of Apache log files, the memory will get freed up
However, an effective way to deal with Apache memory leak is by setting an appropriate value for MaxRequestsPerChild directive in Apache.
MaxRequestsPerChild:
The MaxRequestsPerChild directive sets the limit on the number of requests that an individual child server process will handle. After MaxRequestsPerChild requests, the child process will die.
It is set to 0 by default, the child process will never expire. It is appropriate to set this to a value of few thousands. This can help prevent memory leakage, since the process dies after serving a certain number of requests. Don't set this too low, since creating new processes does have overhead.
For example, set MaxRequestsPerChild 2000 in Apache conf file. Means that after 2000 requests the worker process is shut down and therefore frees up the memory it leaked and locked before.
No comments:
Post a Comment