Making it Better: Basic Apache performance tuning (httpd)

Browse by products and services

  • Applies to: All DV
    • Difficulty: Hard
    • Time Needed: 60
    • Tools Required: None

DV - Making it Better

This article is part of the DV - Making it Better series, which details advanced enhancements and customizations to your DV server.

This article is provided as a courtesy. Installing, configuring, and troubleshooting third-party applications is outside the scope of support provided by (mt) Media Temple. Please take a moment to review the Statement of Support.


This article will provide some basic Apache (httpd) performance tuning. The objective of this article is to perform simple edits that will allow your DV server to run with less memory and to ensure higher availability under heavier loads.


CloudTech Can Help!
(mt) Media Temple offers assisted site migrations via CloudTech, our premium services division. To learn more, please click here.

Adjust prefork settings

The DV server is a fairly forgiving environment for Apache. The prefork settings included in httpd.conf follow a standard linear progression with regards to available RAM and will normally produce suitable results for users. However, servers with heavy resource usage may see improved performance by scaling these settings more conservatively. Additionally, the default Apache build includes a number of modules that are most likely not in use. Removing these from the configuration will free up RAM to be available elsewhere on the server.

The information/suggestions in this article are not steps that need to be done in order. Each set of commands will make changes that may or may not improve performance. However, before proceeding, you will want to make a backup of the files that you modify:

cp -p /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.YYYY-MM-DD.bak


The following change simply scales Apache settings against the available RAM that is outlined by server beancounters. As with any change of this nature, there is no way to guarantee with certainty that it will improve server performance.

This command can be used to lessen the amount of resources that Apache can "run away" with at any one time. For busier servers, this allows you to observe its memory levels change, or if other processes immediately start to make use of the memory which is now available. From there, additional troubleshooting would be necessary to determine if those other processes were problematic in their own right or not.

First, a few variable calculations are required based on current server beancounters. The following commands take the available information from /proc/user_beancounters and returns a number. If your DV has 1G RAM, this number is 2; for 2G RAM, it is 3; so on and so forth:

ramCount=`awk 'match($0,/vmguar/) {print $4}' /proc/user_beancounters`
ramBase=-16 && for ((;ramCount>1;ramBase++)); do ramCount=$((ramCount/2)); done

With this information, adjustments can now be made to the prefork settings in httpd.conf. The following is a single command:

perl -0 -p -i -e 's/(\<IfModule\sprefork\.c\>(\n|[^\n])*?StartServers\s*?)\s\d+/\1\ '"$ramBase"'/;' \
-e 's/(\<IfModule\sprefork\.c\>(\n|[^\n])*?MinSpareServers\s*?)\s\d+/\1\ '"$ramBase"'/;' \
-e 's/(\<IfModule\sprefork\.c\>(\n|[^\n])*?MaxSpareServers\s*?)\s\d+/\1\ '"$(($ramBase*2 + 1))"'/;' \
-e 's/(\<IfModule\sprefork\.c\>(\n|[^\n])*?ServerLimit\s*?)\s\d+/\1\ '"$(( 50 + (($ramBase**2)*10) + (($ramBase-2)*10) ))"'/;' \
-e 's/(\<IfModule\sprefork\.c\>(\n|[^\n])*?MaxClients\s*?)\s\d+/\1\ '"$(( 50 + (($ramBase**2)*10) + (($ramBase-2)*10) ))"'/;' \
-e 's/(\<IfModule\sprefork\.c\>(\n|[^\n])*?MaxRequestsPerChild\s*?)\s\d+/\1\ '"$(( 2048 + ($ramBase*256) ))"'/;' /etc/httpd/conf/httpd.conf

Again, these changes are only suggested settings. Particular users may find better results comparing and contrasting the original backup file with the values that this provides and creating customized settings.

Disabling Unnecessary Apache Modules

These first few commands disable three modules that are loaded into Apache by default with their own configuration files. For users with standard PHP-based applications, these should not be needed, and so they can be prevented from loading into Apache.

mv /etc/httpd/conf.d/perl.conf /etc/httpd/conf.d/perl.conf-disabled
mv /etc/httpd/conf.d/python.conf /etc/httpd/conf.d/python.conf-disabled

The following change removes a number of other modules from Apache. For most users, nothing in this list is needed. However, certain applications or server configurations may require that one or more of these modules be made available.

This command will lessen the resources Apache is claiming each time it needs to spawn a process. Each module loaded requires a slightly bulkier process, which means a higher idle RAM usage. For servers using a large number of Apache processes without any need for these modules, this will free up this RAM for use elsewhere.

The following command is a single command. If you see a module listed that you do not want disabled, simply remove that line from the command before executing it. If you need to re-enable a module afterward, you can manually edit /etc/httpd/conf/httpd.conf and remove the comment (# symbol) in any LoadModule directive that needs to take effect.

perl -0 -p -i \
-e 's/#?(LoadModule\ authn_alias_module\ modules\/mod_authn_alias\.so)/#\1/;' \
-e 's/#?(LoadModule\ authn_anon_module\ modules\/mod_authn_anon\.so)/#\1/;' \
-e 's/#?(LoadModule\ authn_dbm_module\ modules\/mod_authn_dbm\.so)/#\1/;' \
-e 's/#?(LoadModule\ authnz_ldap_module\ modules\/mod_authnz_ldap\.so)/#\1/;' \
-e 's/#?(LoadModule\ authz_dbm_module\ modules\/mod_authz_dbm\.so)/#\1/;' \
-e 's/#?(LoadModule\ authz_owner_module\ modules\/mod_authz_owner\.so)/#\1/;' \
-e 's/#?(LoadModule\ cache_module\ modules\/mod_cache\.so)/#\1/;' \
-e 's/#?(LoadModule\ disk_cache_module\ modules\/mod_disk_cache\.so)/#\1/;' \
-e 's/#?(LoadModule\ ext_filter_module\ modules\/mod_ext_filter\.so)/#\1/;' \
-e 's/#?(LoadModule\ file_cache_module\ modules\/mod_file_cache\.so)/#\1/;' \
-e 's/#?(LoadModule\ info_module\ modules\/mod_info\.so)/#\1/;' \
-e 's/#?(LoadModule\ ldap_module\ modules\/mod_ldap\.so)/#\1/;' \
-e 's/#?(LoadModule\ mem_cache_module\ modules\/mod_mem_cache\.so)/#\1/;' \
-e 's/#?(LoadModule\ status_module\ modules\/mod_status\.so)/#\1/;' \
-e 's/#?(LoadModule\ speling_module\ modules\/mod_speling\.so)/#\1/;' \
-e 's/#?(LoadModule\ usertrack_module\ modules\/mod_usertrack\.so)/#\1/;' -e 's/#?(LoadModule\ version_module\ modules\/mod_version\.so)/#\1/;' /etc/httpd/conf/httpd.conf

Any time you make changes to Apache configurations, you need to restart the server in order for them to take effect:

/etc/init.d/httpd restart

Additional Resources

Please keep in mind that scripted suggestions and automated changes can only go so far. Some level of familiarity with the official Apache documentation can go a long way when addressing web server performance.