Main menu

Apache Performance Tuning Tips

How To Optimize Apache Web Server Performance

Apache Performance Tuning Tips: Apache is a very powerful Web Server, and it’s moulder structure makes it really easy to configure. Modules give us flexibility to use it’s initial configuration, but as our site grows we need to change this configuration to meet our performance requirements.

1. Disable unused module Apache


Checking loaded modules in CentOS/RHEL

[root@localhost]#httpd  -M

By default all modules in Apache is loaded from it’s config file “/etc/httpd/conf/httpd.conf”. Open this file in nano or Vim, search for LoadModule

 LoadModule auth_basic_module modules/

and comment out the module you want to unload or disable.


Checking loaded modules in Ubuntu/Debain

[root@localhost]#apache2ctl -M

Disable a module :

[root@localhost]#sudo a2dismod rewrite

enable a module

[root@localhost]#sudo a2enmod rewrite

2. Hostname lookup : Every time when a request comes to Apache it make a reverse lookup of DNS for finding it’s hostname. If DNS is busy then Apache request become slow automatically. Disable the HostName lookup in Apache

HostnameLookups Off

3. KeepAlive Request : Each connection on Apache alive for a short time and waiting for the request from the same client. It will optimize the user experience. But some time in a busy server there might be many awaiting request which will never occurs. We can enable and disable the setting and can set up the wait time for each request.
# Enable of disbale keep alive request

KeepAlive On

KeepAliveTimeout : How long server wait for the new request from client. Default setting is 15 sec but it should be less to avoid memory wastage on server.

 KeepAliveTimeout 10

MaxKeepAliveRequest: Maximum number of request a KeepAlive persistent connection will server. Most of the cases between 50 to 100 is best

MaxKeepAliveRequest 50

4. Process management :Apache single process is responsible for launching the child process. Apache creates idle spare server process for incoming request. This way client don’t need to wait for child process to be forked.
StartServers: Minimum child process to create at startup. As process is dynamically controlled there less need to configure this.
MinSpareServers : minimum number of idle child process will be created if all process are busy.
MaxSpareServers: maximum number of idle child server processes which is not handling the request. If it’s equal or less them MinSpareServers Apache will automatically increase it by +1.
MaxClients: Maximum number of child process which will be created for incoming request. If we are using KeepAlive On then it should be higher or you will get “Server Unavailable error”.
MaxRequestsPerChild : With KeepAlive On same connection serve many request. This setting define maximum number of request a child process can handle.

 <IfModule mpm_prefork_module>
 StartServers 5
 MinSpareServers 5
 MaxSpareServers 10
 MaxClients 512
 MaxRequestsPerChild 512

Learn more about Apache process management.

Using Compression : Use mod_gzip or mod_deflate for compressing your content before sending to clients browser.
Learn more about compressing your content on Apache2.2 documentation.