A minor (but vital) Apache performance tweak

Last Updated on April 15, 2017 by Dave Farquhar

My problems seem to have become more rare since I started blocking spambots and tuned PHP and Apache but last night my server ran out of memory again and started timing out.

It turns out I still had a critical problem, but one that’s easy to fix with a relatively simple Perl script.

I found a reference to a script called Apachebuddy. Running that, I saw that my MaxClients setting in apache2.conf was likely, under load, to cause Apache to try to use 30% more memory than I have in the system. Never mind that Apache has to share space with a database and an operating system (both somewhat important) on the same box.

So I dropped my MaxClients setting based on the recommendation. (Extrapolating from those results, the default-out-of-the-box Apache settings would use 3.9 GB of memory, which is more than the total available memory in a 32-bit x86 system. Yikes.)

My uptime on Apache when I ran this was artificially low, since Apache had only been running for a few minutes. For a quick fix, that’s fine, but for a more valid test, it would be better to retest after the server has handled some load. The results when Apache had two minutes of uptime were quite a bit different from the results when Apache had 15 minutes of uptime. My site gets enough traffic that 15 minutes seemed to be long enough to get reasonable results. When I first ran it, my largest Apache process was 16 megabytes. After 15 minutes, it was 43 MB, and after 30 minutes, it was 38 MB.

Once I find and correct all of the whacked-out defaults, I need to document all the changes I’ve made in one place. But first I need to get back to the point of not having Windows-like uptimes on my server. Otherwise, all I’m doing is passing along incomplete advice.

If you found this post informative or helpful, please share it!