Linux Network Web

Apache performance tuning for Linux

apache performance tuning
apache performance tuning

Apache is most widely used web server in the world by market-share right now. It’s amazingly flexible when it comes to handle large amount of traffic. Apache performance tuning is the process to utilizing this amazing piece of software according to your needs and infrastructure.

Multi Processing Modules(MPM)

Be sure to back up the configuration file:, before making any changes to your Apache configuration:

Apache comes with several “basic” functions built in, more functionality comes with adding modules to Apache. Modules allow you to add, delete, and edit features for your Apache installation. To see which modules are installed on your Apache server, run the following command.

#http  -l


#apache2 -l

Mainly we have two types of MPM modules, Prefork and Worker.


Prefork MPM launches multiple child processes. Each child process handle one connection at a time.

Prefork module consumes large amount of memory in comparison to worker MPM. Apache web server comes with prefork module as default settings.  Prefork MPM always creates few minim (MinSpareServers) defined processes as spare, so new connections to be created do not need to wait for new process to start.


Worker module creates the multiple child process as Prefork module does. Each child process handles many threads and each thread serves one connection at a time.

In short Worker MPM implements a hybrid multi-process multi-threaded server. Worker module consume less memory in comparison with prefork module.


Module Values

Once you select your MPM, you will need to change the values inside the configuration. These settings are located in the /etc/apache2/apache2.conf file on Debian/Ubuntu, and the /etc/httpd/conf/httpd.conf file on CentOS/Fedora. The MPM looks like this:

<IfModule mpm_prefork_module>
       StartServers          4
       MinSpareServers       20
       MaxSpareServers      40
       MaxClients           200
       MaxRequestsPerChild  4500
</IfModule mpm_prefork_module>

Apache performance tuning for Linux

Below are the key parameters that needs to be tweaked for Apache performance tuning. These Apache directives impact the performance of Apache HTTP Web server ( and other servers based on Apache web server like IBM HTTP Server etc). We will also see how live server’s status and performance can be monitored.

  • Timeout
  • MaxKeepAliveRequests
  • StartServers
  • ThreadLimit
  • ServerLimit
  • KeepAlive
  • KeepAliveTimeout
  • ThreadsPerChild
  • MaxClients
  • MaxRequestsPerChild

Apache performance tuning Directives


  • Timeout directive will set the time for server will wait for certain events before failing a request.
  • When reading data from the client, the length of time to wait for a TCP packet to arrive if the read buffer is empty.
  • When writing data to the client, the length of time to wait for an acknowledgment of a packet if the send buffer is full.


  • KeepAlive directive Provide long-long lived HTTP Sessions which allow multiple requests to be sent over the same TCP connection.
  • In some cases this has been shown to result in an almost 50% speedup in latency time for HTML documents with many images.


  • The MaxKeepAliveRequests directive limits the number of requests allowed per connection when KeepAlive is on.
  • If it is set to 0, unlimited requests will be allowed.
  • Generally, higher the value will provide better results.


  • The number of seconds Apache will wait for a subsequent request before closing the connection. Once a request has been received, the timeout value specified by the Timeout directive applies.
  • Setting KeepAliveTimeout to a high value may cause performance problems in heavily loaded servers. The higher the timeout, the more server processes will be kept occupied waiting on connections with idle clients.


  • This directive sets the number of threads to be created on startup.
  • As the number of threads is dynamically controlled depending on the load, there is usually little reason to adjust this parameter.


  • This directive sets the number of threads created by each child process.
  • The child creates these threads at startup and never creates more.


  • Sets the upper limit on the configurable number of threads per child process(ThreadsPerChild)
  • Special care must be taken when using this directive.
  • If  ThreadLimit is set to a value much higher than ThreadsPerChild, extra unused shared memory will be allocated.
  • If both ThreadLimit and ThreadsPerChild are set to values higher than the system can handle. Apache may not start or the system may become unusable.


  • MaxClients is one of the most important directive in Apache configuration.
  • Directly impacts the maximum concurrent clients or connection, which can be established with web server.
  • The MaxClients directive sets the limit on the number of simultaneous requests that will be served.
  • Any client request received, once MaxClients is reached, will be queued up.
  • Once a child process is freed at the end of a different requests, the connections will then be serviced.


  • Upper limit on the number of process.
  • ServerLmit directive in combination with ThreadLimit sets the maximum configured value for MaxClients(if ServerLimit is 10, ThreadLimit is 10, MaxClients will be 100)
  • If ServerLimit is set to a value much higher than necessary, extra unused shared memory will be allocated.
  • If both ServerLimit and MaxClients are set to values higher than  the system can handle, Apache may not start or the system may become unstable.


  • The MaxRequestsPerChild directive sets the limit on the number of request that an individual child server processes will handle.
  • After MaxRequestsPerChild requests, the child process will die.
  • If MaxRequestsPerChild is 0, then the process will never expire.


About the author

Ajay Verma

A Computer Science Graduate, who works extensively on open source projects. His Areas Of interest are: Network Security, Linux Administration, FOSS, Python, and C programming.


Click here to post a comment