Product SiteDocumentation Site

2.3. Performance Tuning Introduction

Apache is the type of application that, during its lifetime as an application, can do the same thing millions of times over and over again. The result is that apache is an ideal application for tuning. When done properly tuning is as much science as it can be though its not perfect. This imperfection is where a skilled admin can make educated guesses. This art comes from things like not knowing when someone will /. you, or how many people will actually respond to the last mass mailing that was sent out.
This standard focuses not on getting every last drop out of a host until it crashes. Instead this standard focuses on setting values to a known max utilization. Once this utilization is hit, users will start to experience timeouts and slow connects or connection refused messages. Even at this fully utilized state the box will remain responsive. This has a few key benefits over letting the box get completely consumed and exiting on its own. The first of which is that administrators can still log in and examine the box while it is fully utilized allowing them to determine if something is configured incorrectly or if the number of resources assigned to this server are incorrect (for example, it needs more memory). The second advantage is that the box stays up and does continue to serve requests. The alternative is a box completely crashing turning all users away immediately. The theory being its better to have slow responses for a while then no responses for a while. It also gives the box better odds to recover from the load spike on its own.

2.3.1. httpd config settings

This section focuses on settings in /etc/httpd/conf/httpd.conf. MaxClients - ServerLimit

MaxClients - Maximum number of simultaneous requests that will be served
ServerLimit - Upper limit on configurable number of processes Usable Ram
To determine the proper values for MaxClients and ServerLimit first you need to understand that we're trying to limit MaxClients and MaxServers based on some given amount of memory. According to the Apache docs “The single biggest hardware issue affecting webserver performance is RAM.” The easiest way to determine usable ram is to stop httpd, then find how much free memory there is on the host excluding buffers. This value can be determined by free | awk '/buffers\/cache/ { print $4 }' This value is in kilobytes. Buffer Size
We don't want apache to just take up whatever free memory there is because this would leave no room for buffers. Generally we'll leave 15% of UsableRam for buffers.
UsableRam * .15
Equation 2.1. BufferSize



For many servers that don't do much disk IO you can leave less, like 10% (Like those servers reading and writing most of their information to a database. For servers that do a great deal of disk IO it is best to leave this a bit higher, at 20% or more. Apache Ram
ApacheRam is the amount of ram we're going to target for Apache use.
UsableRam - BufferSize
Equation 2.2. ApacheRam Average Httpd Size
Every httpd process takes up a certain amount of ram. Some of this memory is in shared memory, some of it is unique to each httpd process. To determine average httpd size we look at the size of each httpd process minus the shared memory size. To determine this size run echo $(($(for f in `pgrep httpd`; do awk '/Rss/ { rss+=$2 } /Shared/ { shared+=$2 } END { print rss-shared }' /proc/$f/smaps 2> /dev/null; done | awk '{ s+=$1 } END { print s }') / $(pgrep httpd | wc -l)))


If stability is more important to you then performance. Add an additional 10% to this number.
AverageHttpdSize * 1.1
Equation 2.3. AverageHttpdSize MaxClients
To determine how high to set MaxClients in the actual httpd.conf file use the ApacheRam size and divide it by AverageHttpdSize.
ApacheRam / AverageHttpdSize
Equation 2.4. MaxClients ServerLimit
ServerLimit is more like a hard limit to MaxClients. This should be about 1% higher then MaxClients.
MaxClients * 1.1
Equation 2.5. ServerLimit