Apache script for low memory installation

apache-2.2memory usageoptimization

I've been working on improving memory usage on our Centos 5.5 VDS, which now has 512MB of RAM. I've been able to use a tuneup script to greatly improve the MySQL config but am having a bit more trouble getting Apache's memory usage down. Part of my problem is conflicting advice on a various web sites, forums, etc. Being a production server the normal modify and test cycle I would employ on a test machine would be a bit too disruptive.

To add to my confusion, I have a dev machine configured as near as I can make it to be a clone of the VDS and it uses less RAM with the exact same Apache configuration. Although it's obviously difficult to apply the same load I get pretty close when comparing the two during the quiet times of the day or night.

Is there a tuneup script for Apache, like those available for MySQL, that can help optimize the configuration by analyzing what's happening while the server is running?

Edit:

Either I've been unclear or people are not reading the question, so I'll clarify.

I'm not asking anyone here to make recommendations or suggest alternatives. I'm asking if someone here knows of a script which can analyze what's happening on the server and make recommendations regarding the Apache configuration based on that information.

Best Answer

I don't know of any such script for Apache likely because, compared to MySQL, there are only a few things which affect Apache's memory usage:

  1. MaxClients: The more clients the more memory used.
  2. Mods: Similarly, the more mods/extensions installed the more memory needed.
  3. Dynamic Scripts: Running dynamic scripts, like PHP, may increase memory usage depending on your Apache settings. For example, say you have 10 small PHP files and one rarely used large/memory intensive one. Eventually all Apache clients will run this large PHP script and use more memory.
  4. Compile Time: I haven't played much with Apache compile time settings but I wouldn't be surprised if there were some memory savings to be found there.

A few specific things you can try are listed below. Try to measure the effect and test on your development platform first if possible and/or implement any changes gradually on the production site.

  1. Keep MaxClients as low as possible. On a low volume site you can likely get away with numbers well under 10. You can also keep other related settings like MaxSpareServers low.
  2. Compare the prefork vs worker modes of Apache to see if there's any significant difference in memory usage.
  3. Eliminate all mods/extensions you are not actually using. This may be more difficult than it sounds as it is not always easy to determine which ones you are using.
  4. Use a low value (100-1000) for MaxRequestsPerChild if you are using any dynamic scripts or are seeings the Apache instances slowing increasing in memory usage over time. This stops memory hungry or leaking scripts from using up too much memory.
  5. Look into compile time memory optimizations only if you really need to, or have a lot of past experience compiling Apache. Personally I would look into alternative servers before this step.
Related Topic