Theserve Blog

web hosting and virtual server blogApache memory usage on a VPS

Posted On: 6th January 2012 under vps

We were asked buy a customer to help them run Apache with a minimal footprint as they were hitting the limits of their virtual server and didn't want to upgrade for such a small website.

When memory is precious, which it can be in some of the most basic virtual server packages, Apache can be a bit of a memory hog. We helped our customer by reducing the memory footprint slight in 2 ways:

  1. We disabled all the modules that Apache didn't need.
  2. We reduced the number of spare threads Apache had waiting.

For the minimal config to run we had the following modules enabled:

LoadModule authz_host_module modules/mod_authz_host.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so

This was based on the default Centos Apache config file. You could probably remove some more if you spent time removing any references to the modules in the config file.

In addition to reduce the minimum spare servers we adjusted the following:

<IfModule prefork.c>
StartServers       4
MinSpareServers    2
MaxSpareServers   10
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000
</IfModule>

This minimal configuration may not be the best for busier websites but for a small static website it will operate just fine. By making these changes we managed to reduce the memory footprint enough for the customer to run their additional services and keep within their memory limits.