Every now and then my web sites’ traffic (and the load on the servers) increases to the point where I have to do something about it. I start finding out whatever I can about optimizing Apache, MySQL, PHP, and other components, simplify my code and database queries as much as possible, then if that fails, start pricing higher-powered servers.
Last time this happened, a few months ago, the main server was running out of memory and nearly crashing several times a day. I ran across this O’Reilly article on tuning Linux web servers and followed a few of the suggestions that were new to me.
One thing that really helped: it seems that Apache threads gradually increase their memory allocation as they run, depending on what dynamic code you run with them. Setting the MaxRequestsPerChild parameter in httpd.conf forces it to start new threads periodically, and this memory growth process starts over. (I used the value 200, but you need to experiment with your server.)
It’s only a temporary measure, but this kept the server running smoothly for the last few months. The server load reached 20 (very bad) on a typical day before the change, and stayed around 5 (slightly bad) after.
Now traffic levels and server load have nearly reached critical again, so it’s back to the drawing board… Anyone got any amazing apache speedups?