How to optimization Apache

Ideal place for discussions related to Linux/Windows server security, Apache, MySQL, MS SQL and PHP, including tutorials and questions.
Site Admin
Posts: 50
Joined: Thu May 30, 2013 10:28 pm

How to optimization Apache

Postby hrdedicated » Sat Jun 01, 2013 12:22 pm

Apache optimization


Apache 2.x is a general-purpose webserver, designed to provide a balance of flexibility, portability, and performance. Although it has not been designed specifically to set benchmark records, Apache 2.x is capable of high performance in many real-world situations.
Compared to Apache 1.3, release 2.x contains many additional optimizations to increase throughput and scalability. Most of these improvements are enabled by default. However, there are compile-time and run-time configuration choices that can significantly affect performance. This document describes the options that a server administrator can configure to tune the performance of an Apache 2.x installation. Some of these configuration options enable the httpd to better take advantage of the capabilities of the hardware and OS, while others allow the administrator to trade functionality for speed
Apache is typically structured as a pool of workers that handle HTTP
Requests enter the TCP Accept Queue where they wait for a worker. A worker
processes a single request to completion before accepting a new request.
Below given are the apache directives that can be tweaked to achive better
You can find all these options in httpd.conf file on the server. Take a backup of httpd.conf, before making any changes in it.


1. Login to server via ssh as root user.
2. Then, vi /usr/local/apache/conf/httpd.conf and search for following.


The number of worker processes is limited by the parameter MaxClients.
MaxClients = Total RAM dedicated to the web server / Max child process size.
The default value of MaxClients is 150.
If we have a server with 1 GB of ram and child process take an average size
of 20 mb.
We can set the MaxClients as 1024/20 = 52
The StartServers directive sets the number of child server processes created
on startup. As the number of processes is dynamically controlled depending on
the load, there is usually little reason to adjust this parameter.
The default value is 5, which is enough for most of the situations. We can
try lowering this value in extreme cases.
The MinSpareServers directive sets the desired minimum number of idle child
server processes. An idle process is one which is not handling a request. If
there are fewer than MinSpareServers idle, then the parent process creates
new children at a maximum rate of 1 per second.
Tuning of this parameter should only be necessary on very busy sites. Setting
this parameter to a large number is almost always a bad idea.
The default value is 5. We can try lowering this value inorder to reduce the
The MaxSpareServers directive sets the desired maximum number of idle child
server processes. An idle process is one which is not handling a request. If
there are more than MaxSpareServers idle, then the parent process will kill
off the excess processes.
Tuning of this parameter should only be necessary on very busy sites. Setting
this parameter to a large number is almost always a bad idea. If you are
trying to set the value lower than MinSpareServers, Apache will automatically
adjust it to MinSpareServers + 1.
The default value is 10.
The MaxRequestsPerChild directive sets the limit on the number of requests
that an individual child server process will handle. After
MaxRequestsPerChild requests, the child process will die. If
MaxRequestsPerChild is 0, then the process will never expire.
The default option is set as 0, that is the process will never expire.
Usually setting this value as 250-500 is preferable.
The Keep-Alive extension 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 times for HTML documents with many images. To enable
Keep-Alive connections, set KeepAlive On.
The dynamic content such as CGI output, SSI pages, and server-generated
directory listings will generally not use Keep-Alive connections .
If we are getting too many connection timedd out error it is better to turn
this option off.
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.
Determines whether Apache does a reverse DNS lookup on
client addresses so it can write hostnames in the logfile.
A lot of people turn this on so they can have country reports
etc in their traffic reports.
The default is Off in order to save the network traffic for those sites that
don’t truly need the reverse lookups done. It is also better for the end
users because they don’t have to suffer the extra latency that a lookup
Heavily loaded sites should leave this directive Off, since DNS lookups can
take considerable amounts of time. The utility logresolve, compiled by
default to the bin subdirectory of your installation directory, can be used
to look up host names from logged IP addresses offline.

Return to “System Security”

Who is online

Users browsing this forum: No registered users and 1 guest