Your Domain search

Optimizing Apache

The efficiency with which Apache runs with can be greatly improved with a few small tweaks in the Apache configuration file. Below are the major parameters that can be tweaked to improve the performance of the server.

  • Timeout: This directive is used to define the amount of time Apache will wait for a GET, POST, PUT request and acknowledges on transmissions before automatically disconnecting, when idle time exceeds this value. This value is set to 120 to improve performance in heavily loaded servers. It is recommended to set this value lower if your clients have low latencies. Some times, setting this directive to a low value may cause problems, depending on your network and server setup. The best option is to experiment with different values to find the one that fits your need.

  • KeepAlive: This directive, if set to On, enables persistent connections on the web server. For better performance, it is recommended to set this option to On and allow more than one request per connection. In the original HTTP specification, every HTTP request had to establish a separate connection to the server. This reduced the overhead of frequent connects to the server for multiple HTTP requests.

  • MaxKeepAliveRequests: This directive is used to define the number of requests allowed per connection when the KeepAlive option is set to On. Socket connections will be terminated when the number of requests set by the MaxKeepAliveRequests directive is reached. When the value of this option is set to 0, unlimited requests are allowed on the server. For server performance, it is recommended to allow unlimited requests.

  • KeepAliveTimeout: This directive is used to define how much time (in 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. The value of 10 seconds is a good average for server performance. This value should be kept low as the socket will be idle for extended periods otherwise.

  • StartServers: This directive is used to define the number of child server processes that will be created by Apache on start-up. As the number of processes with Apache 2.x is dynamically controlled depending on the load, there is usually little reason to adjust this parameter now. Normally a default value of 5 is set for this parameter.

  • MaxClients: This directive is used to define the limit on the number of child processes that will be created to serve requests. By default, up to 512 HTTP requests can be handled concurrently. Any further connection requests are queued. For high load operation, a value of 512 is recommended. For standard use, you can set the value to 256.

  • ServerLimit: This directive is used to define the maximum configured value for the MaxClients directive for the lifetime of the Apache process. It is important to note that any attempts to change this directive during a restart will be ignored, but the MaxClients directive can be modified during a restart of the server. For high load operation, a value of 1024 is highly recommended. For standard use, you can set the value to 256.

    Special care must be taken when using this directive. If it is set to a value much higher than necessary, extra, unused shared memory will be allocated. If both ServerLimit and MaxClients directives are set to values higher than the system can handle, Apache may not start or the system may become unstable.

  • MinSpareServers: This directive is used to define the minimum number of idle child server processes that should be created. An idle process is one which is not handling a request. If there are fewer idle processes than the MinSpareServers value, the parent process creates new children at a maximum rate of 1 per second.

  • MaxSpareServers: This directive is used to define the maximum number of idle child server processes that should be created. If there are more idle processes than the MaxSpareServers value, then the parent process will kill off the excess processes and these extra processes will be terminated.

  • MaxRequestsPerChild: This option is used to define the number of requests that an individual child server process will handle. This value can be set to 0 to get the maximum performance and scalability for the server.