From: Igor Galić The Performance Tuning page in the Apache 1.3 documentation says:
+ “Apache is a general webserver, which is designed to be
correct first, and fast
second. Even so, its performance is quite satisfactory. Most
sites have less than 10Mbits of outgoing bandwidth, which
Apache can fill using only a low end Pentium-based
- webserver.”
-
-
+ webserver.”
However, this sentence was written a few years ago, and in the meantime several things have happened. On one hand, web server hardware has become much faster. On the other hand, many sites now @@ -104,7 +103,7 @@
The top tool ships with Linux and FreeBSD. Solaris offers
- `prstat'. It collects a number of statistics for the
+ prstat(1)
. It collects a number of statistics for the
system and for each running process, then displays them
interactively on your terminal. The data displayed is
refreshed every second and varies by platform, but
@@ -192,10 +191,8 @@
top ten CPU gluttons). It is indispensable in determining
the size of a running process, which comes in handy when
determining how many server processes you can run on your
- machine. How to do this is described in '
- sizing MaxClients
-
- '. Top is, however, an interactive tool and running it
+ machine. How to do this is described in sizing MaxClients.
+ Top is, however, an interactive tool and running it
continuously has few if any advantages.
@@ -230,9 +225,8 @@
displays a large number of operating system metrics. Run
without argument, it displays a status line for that
moment. When a numeric argument is added, the status is
- redisplayed at designated intervals. For example,
- vmstat 5
-
+ redisplayed at designated intervals. For example,
+ vmstat 5
causes the information to reappear every five seconds.
Vmstat displays the amount of virtual memory in use, how
much memory is swapped in and out each second, the number
@@ -241,9 +235,7 @@
percentages of the CPU.
- The following is vmstat
-
- output of an idle server:
+ The following is vmstat
output of an idle server:
ExtendedStatus On
-
- directive in your httpd.conf
-
- ,the mod_status
-
+ Foundation uses mod_status
on its own
+ web site.
+ If you put the ExtendedStatus On
+ directive in your httpd.conf
,
+ the mod_status
page will give you more information at the cost of a little
extra work per request.
@@ -383,24 +371,20 @@
this error information will appear on your terminal and you
can use it directly to troubleshoot your server. If your
httpd is started by a startup script, the destination of
- early error messages depends on their design. The
- /var/log/messages
-
+ early error messages depends on their design. The
+ /var/log/messages
file is usually a good bet. On Windows, early error
messages are written to the Applications Event Log, which
can be viewed through the Event Viewer in Administrative
Tools.
- The Error Log is configured through the ErrorLog
-
- and LogLevel
-
+ The Error Log is configured through the ErrorLog
+ and LogLevel
configuration directives. The error log of httpd’s main
server configuration receives the log messages that pertain
to the entire server: startup, shutdown, crashes, excessive
- process spawns, etc. The ErrorLog
-
+ process spawns, etc. The ErrorLog
directive can also be used in virtual host containers. The
error log of a virtual host receives only log messages
specific to that virtual host, such as authentication
@@ -413,118 +397,92 @@
attack scripts just throw everything they have at any open
port, regardless of which server is actually running or
what applications might be installed. You could block these
- attempts using a firewall or
- mod_security
-
- ,but this falls outside the scope of this discussion.
+ attempts using a firewall or mod_security,
+ but this falls outside the scope of this discussion.
- The LogLevel
-
+ The LogLevel
directive determines the level of detail included in the
logs. There are eight log levels as described here:
- - Level - - +Level |
- - Description - - +Description |
- emerg - +emerg |
- Emergencies - system is unusable. - +Emergencies - system is unusable. |
- alert - +alert |
- Action must be taken immediately. - +Action must be taken immediately. |
- crit - +crit |
- Critical Conditions. - +Critical Conditions. |
- error - +error |
- Error conditions. - +Error conditions. |
- warn - +warn |
- Warning conditions. - +Warning conditions. |
- notice - +notice |
- Normal but significant condition. - +Normal but significant condition. |
- info - +info |
- Informational. - +Informational. |
- debug - +debug |
- Debug-level messages - +Debug-level messages |
The default log level is warn. A production server should
not be run on debug, but increasing the level of detail in
the error log can be useful during troubleshooting.
- Starting with 2.3.8 LogLevel
-
+ Starting with 2.3.8 LogLevel
can be specified on a per module basis:
- This puts all of the server in debug mode, except for
- mod_ssl
-
- ,which tends to be very noisy.
+ This puts all of the server in debug mode, except for
+ mod_ssl
, which tends to be very noisy.
TransferLog
-
- or CustomLog
-
+ The various logging format features are documented in the
+ manual. This file exists by default for the main server and can be
+ configured per virtual host by using the TransferLog
+ or CustomLog
configuration directive.
The access logs can be analyzed with any of several free and @@ -588,121 +540,90 @@
- - Field - - +Field |
- - Content - - +Content |
- - Explanation - - +Explanation |
- Client IP - +Client IP |
- 195.54.228.42 - +195.54.228.42 |
- IP address where the request originated - +IP address where the request originated |
- RFC 1413 ident - +RFC 1413 ident |
- - - +- |
- Remote user identity as reported by their - identd - +Remote user identity as reported by their identd |
- username - +username |
- - - +- |
- Remote username as authenticated by Apache - +Remote username as authenticated by Apache |
- timestamp - +timestamp |
- [24/Mar/2007:23:05:11 -0400] - +[24/Mar/2007:23:05:11 -0400] |
- Date and time of request - +Date and time of request |
- Request - +Request |
- "GET /sander/feed/ HTTP/1.1" - +"GET /sander/feed/ HTTP/1.1" |
- Request line - +Request line |
- Status Code - +Status Code |
- 200 - +200 |
- Response code - +Response code |
- Content Bytes - +Content Bytes |
- 9747 - +9747 |
- Bytes transferred w/o headers - +Bytes transferred w/o headers |
- A second approach is to use piped logs. From the
- CustomLog
-
- ,TransferLog
-
- or ErrorLog
-
+ A second approach is to use piped logs. From the
+ CustomLog
,
+ TransferLog
+ or ErrorLog
+
directives you can send the log data into any program using
- a pipe character (|
-
- ). For instance:
+ a pipe character (|
). For instance:
CustomLog "|/usr/local/apache2/bin/rotatelogs
@@ -796,10 +713,8 @@
disk sequentially.
- Do not run a production server with your error
- LogLevel
-
- set to debug. This log level causes a vast amount of
+ Do not run a production server with your error LogLevel
+ set to debug. This log level causes a vast amount of
information to be written to the error log, including, in
the case of SSL access, complete dumps of BIO read and
write operations. The performance implications are
@@ -820,8 +735,7 @@
under support/split-logfile
.
- You can use the BufferedLogs
-
+ You can use the BufferedLogs
directive to have Apache collect several log lines in
memory before writing them to disk. This might yield better
performance, but could affect the order in which the
@@ -974,8 +888,7 @@
that all the memory on your system is used, but no more. If
your system gets so overloaded that it needs to heavily
swap core memory out to disk, performance will degrade
- quickly. The formula for determining MaxClients
-
+ quickly. The formula for determining MaxClients
is fairly simple:
/etc/login.conf
these resources can be limited or extended system wide,
- analogously to limits.conf
-
- .'Soft' limits can be specified with -cur
-
- and 'hard' limits with -max
-
- .
+ analogously to limits.conf
.
+ 'Soft' limits can be specified with -cur
+ and 'hard' limits with -max
.
Solaris has a similar mechanism for manipulating limit
- values at boot time: In /etc/system
-
+ values at boot time: In /etc/system
you can set kernel tunables valid for the entire system at
boot time. These are the same tunables that can be set with
- the mdb
-
+ the mdb
kernel debugger during run time. The soft and hard limit
corresponding to ulimit -u can be set via:
Solaris calculates the maximum number of allowed processes
- per user (maxuprc
-
- )based on the total amount available memory on the system (
- maxusers
-
- ). You can review the numbers with
+ per user (maxuprc
) based on the total amount
+ available memory on the system (maxusers
).
+ You can review the numbers with
sysdef -i | grep maximum
@@ -1345,26 +1249,21 @@
etc. Turn them off.
On Red Hat Linux, the chkconfig tool will help you do this
- from the command line. On Solaris systems svcs
-
- and svcadm
-
+ from the command line. On Solaris systems svcs
+ and svcadm
will show which services are enabled and disable them
respectively.
In a similar fashion, cast a critical eye on the Apache
modules you load. Most binary distributions of Apache
httpd, and pre-installed versions that come with Linux
- distributions, have their modules enabled through the
- LoadModule
-
- directive.
+ distributions, have their modules enabled through the
+ LoadModule
directive.
Unused modules may be culled: if you don't rely on
their functionality and configuration directives, you can
- turn them off by commenting out the corresponding
- LoadModule
-
+ turn them off by commenting out the corresponding
+ LoadModule
lines. Read the documentation on each module’s
functionality before deciding whether to keep it enabled.
While the performance overhead of an unused module is
@@ -1416,12 +1315,8 @@
- 'we should provide a more useful example here. - One showing how to make Wordpress or Drupal suck less. - - ' -
+ +Blosxom is a lightweight web log package that runs as a CGI. It is written in Perl and uses plain text files for entry input. Besides running as CGI, Blosxom can be run from the @@ -1432,8 +1327,7 @@
To run blosxom for static page generation, edit the CGI
script according to the documentation. Set the $static dir
- variable to the DocumentRoot
-
+ variable to the DocumentRoot
of the web server, and run the script from the command line
as follows:
- --enable-rewrite[=shared]
-
+ the server by passing the option --enable-rewrite[=shared]
to the configure command. Many binary distributions of
- Apache come with mod_rewrite included. The following is an
+ Apache come with mod_rewrite
included. The following is an
example of an Apache virtual host that takes advantage of
pre-rendered blog pages:
@@ -1493,10 +1385,8 @@
- The RewriteCond
-
- and RewriteRule
-
+ The RewriteCond
+ and RewriteRule
directives say that, if the requested resource does not
exist as a file or a directory, its path is passed to the
Blosxom CGI for rendering. Blosxom uses Path Info to
@@ -1535,34 +1425,25 @@
To enable efficient content caching and avoid presenting the
user with stale or invalid content, the application that
generates the actual content has to send the correct response
- headers. Without headers like Etag:
-
- ,Last-Modified:
-
- or Expires:
-
- ,mod_cache can not make the right decision on whether to cache
+ headers. Without headers like Etag:
,
+ Last-Modified:
or Expires:
,
+ mod_cache
can not make the right decision on whether to cache
the content, serve it from cache or leave it alone. When
testing content caching, you may find that you need to modify
your application or, if this is impossible, selectively disable
caching for URLs that cause problems. The mod_cache modules are
not compiled by default, but can be enabled by passing the
- option --enable-cache[=shared]
-
+ option --enable-cache[=shared]
to the configure script. If you use a binary distribution of
Apache httpd, or it came with your port or package collection,
- it may have mod_cache already included.
+ it may have mod_cache
already included.
- 'Is this still the case? Maybe we should give - a better example here too. - -
+
The Apache Software Foundation Wiki is served by MoinMoin.
MoinMoin is written in Python and runs as a CGI. To date, any
@@ -1578,9 +1459,7 @@
the corresponding Python modules were patched to send the
proper HTTP response headers. After this modification, the
cache in front of the Wiki was enabled with the following
- configuration snippet in httpd.conf
-
- :
+ configuration snippet in httpd.conf
:
This configuration will try to cache any and all content
within its virtual host. It will never cache content for
- more than six hours (the
- Do note that it can pay off to disable
-
- the
@@ -1594,29 +1473,22 @@
CacheMaxExpire
-
- directive). If no Expires:
-
- header is present in the response, mod_cache will compute
- an expiration period from the Last-Modified:
-
- header. The computation using CacheLastModifiedFactor
-
+ more than six hours (the CacheMaxExpire
+ directive). If no Expires:
+ header is present in the response, mod_cache
will compute
+ an expiration period from the Last-Modified:
+ header. The computation using CacheLastModifiedFactor
is based on the assumption that if a page was recently
modified, it is likely to change again in the near future
and will have to be re-cached.
ETag:
-
+ Do note that it can pay off to disable
+ the ETag:
header: For files smaller than 1k the server has to
- calculate the checksum (usually MD5) and then send out a
- 304 Not Modified
-
- response, which will take waste some CPU and still saturate
+ calculate the checksum (usually MD5) and then send out a
+ 304 Not Modified
+ response, which will use up some CPU and still saturate
the same amount of network resources for the transfer (one
TCP packet). For resources larger than 1k it might prove
CPU expensive to calculate the header for each request.
@@ -1632,8 +1504,7 @@
- This will disable the generation of the ETag:
-
+ This will disable the generation of the ETag:
header for most static resources. The server does not
calculate these headers for dynamic resources.
Armed with the knowledge of how to tune a sytem to deliver the - desired the performance, we will soon discover that one - + desired the performance, we will soon discover that one system might prove a bottleneck. How to make a system fit for growth, or how to put a number of systems into tune will be - discussed in - PerformanceScalingOut - - . + discussed in PerformanceScalingOut.