Apache HTTP Server Version 2.4
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.
The single biggest hardware issue affecting webserver
performance is RAM. A webserver should never ever have to swap,
as swapping increases the latency of each request beyond a point
that users consider "fast enough". This causes users to hit
stop and reload, further increasing the load. You can, and
should, control the MaxRequestWorkers
setting so that your server
does not spawn so many children that it starts swapping. The 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.
Beyond that the rest is mundane: get a fast enough CPU, a fast enough network card, and fast enough disks, where "fast enough" is something that needs to be determined by experimentation.
Operating system choice is largely a matter of local concerns. But some guidelines that have proven generally useful are:
Run the latest stable release and patch level of the operating system that you choose. Many OS suppliers have introduced significant performance improvements to their TCP stacks and thread libraries in recent years.
If your OS supports a sendfile(2)
system
call, make sure you install the release and/or patches
needed to enable it. (With Linux, for example, this means
using Linux 2.4 or later. For early releases of Solaris 8,
you may need to apply a patch.) On systems where it is
available, sendfile
enables Apache 2 to deliver
static content faster and with lower CPU utilization.
Related Modules | Related Directives |
---|---|
Prior to Apache 1.3, HostnameLookups
defaulted to On
.
This adds latency to every request because it requires a
DNS lookup to complete before the request is finished. In
Apache 1.3 this setting defaults to Off
. If you need
to have addresses in your log files resolved to hostnames, use the
logresolve
program that comes with Apache, or one of the numerous log
reporting packages which are available.
It is recommended that you do this sort of postprocessing of your log files on some machine other than the production web server machine, in order that this activity not adversely affect server performance.
If you use any
or Allow
from domain
directives (i.e., using a hostname, or a domain name, rather than
an IP address) then you will pay for
two DNS lookups (a reverse, followed by a forward lookup
to make sure that the reverse is not being spoofed). For best
performance, therefore, use IP addresses, rather than names, when
using these directives, if possible.Deny
from domain
Note that it's possible to scope the directives, such as
within a <Location "/server-status">
section.
In this case the DNS lookups are only performed on requests
matching the criteria. Here's an example which disables lookups
except for .html
and .cgi
files:
HostnameLookups off <Files ~ "\.(html|cgi)$"> HostnameLookups on </Files>
But even still, if you just need DNS names in some CGIs you
could consider doing the gethostbyname
call in the
specific CGIs that need it.
Wherever in your URL-space you do not have an Options
FollowSymLinks
, or you do have an Options
SymLinksIfOwnerMatch
, Apache will need to issue extra
system calls to check up on symlinks. (One extra call per
filename component.) For example, if you had:
DocumentRoot "/www/htdocs" <Directory "/"> Options SymLinksIfOwnerMatch </Directory>
and a request is made for the URI /index.html
,
then Apache will perform lstat(2)
on
/www
, /www/htdocs
, and
/www/htdocs/index.html
. The results of these
lstats
are never cached, so they will occur on
every single request. If you really desire the symlinks
security checking,