Performance Tuning Apache the SingleHop Way

Apache 2.x is designed to balance flexibility, performance and portability. Apache is a good all-purpose web server. Since Apache is designed to fit most scenarios it hasn't been optimized to set any kind of speed records, but Apache 2.x is capable of high performance.

There have been many improvements made in Apache 2.x and many are enabled by default. But, there are some changes you can make at compile-time and run-time that can positively affect performance.

RAM is the single biggest hardware issue that determines web server performance, so the more the better. Once a server runs out of memory it starts using the swap space on the hard drive. You never ever want have to the web server use swap. Using swap slows down of each request to such slow speeds which causes users to hit reloadÂť, which increases the work swap has to do, slowing it further.
So I always recommend putting in as much ram as your server can hold.

The rest of the hardware is up to you: get a fast CPU, a fast network card, and fast hard drives, you'll have to figure out what is fast enough for you based on needs, availability and price.

You can counter, and should, control the MaxClients setting so that your server does not spawn so many children it starts swapping. This procedure for doing this is simple: determine the size of your average Apache process, by looking at your process list via a tool such as top, and divide this into your total available memory, leaving some room for other processes.

So lets go through some of the simple httpd.conf changes you can make to tune apache for higher performance.

Timeout - Is the number of seconds before receives and sends time out. By decreasing it to 15 seconds we can offset effects of a denial of service attack/server load

KeepAlive - This allows multiple requests to be sent over the same connection, which is useful when serving HTML pages with a lot of images. So make sure KeepAlive is turned ON. eepAlive

MaxKeepAliveRequests – This is the maximum requests allowed during a persistent connection. Zero allows an unlimited amount, so use a high number, for maximum performance

KeepAliveTimeout – This determines how long the server waits for the next request, put this on at a low value between two to five seconds

StartServers - This controls the number of child-processes that Apache spawns before accepting connections. Put this StartServers and MinSpareServers on high numbers,so if there's a high load after restarting the server, there will be plenty of servers ready to serve requests.

MaxSpareServers and MinSpareServers – This tells apache how many processes to keep waiting for requests. Set this number high so apache wont have have to create new child processes to serve requests.

MaxClients – This is maximum simultaneous requests that the server can support. This number should be tuned very well. Too low and new connections end up in a queue and eventually time out, leaving unused resources. Set it too hight and the server will start using swap space and the response time with drop drastically.
So the trick is to properly calculated.

MaxClients = Total RAM dedicated to the web server / Max child process size

However if you need to configure more than 256 clients, you will have to edit the HARD_SERVER_LIMIT entry in httpd.h and recompile Apache

Here is an example of the numbers you should be using.
Timeout 15
KeepAlive On
maxKeepAliveRequests 100
KeepAliveTimeout 3
StartServers 8
MinSpareServers 10
MaxSpareServers 20
MaxClients 250
MaxRequestsPerChild 0

There are other things you can do to speed up apache but we will go over that next time.
If you have any problems setting this up on your server please submit a ticket to your support team at We are here to help.