Scott Wiersdorf Wed Nov 19 01:01:14 MST 2003 $Id: tuning.html,v 1.4 2004/04/08 06:24:10 scott Exp $
KeepAlives, from the manual, "provide long-lived HTTP sessions which 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".
If the typical HTTP "hit profile" on your site does not involve multiple HTTP requests (see example below), you won't benefit from KeepAlives because once the request has been served (and no more are expected from this client for serveral seconds), the socket remains open, unused and consuming server resources that could otherwise be used for other connections. This is what is happening while your site is being very slow: the server is waiting for all those KeepAlive connections to "time out" so it can server other clients.
Example: Your typical request is for a web page and several dozen
images. It usually takes your If your average client is a broadband user OR for whatever reason
you can see that the average total request per page (including images
and other dependencies) is only 2 seconds, then you should reduce your
timeout to 2 seconds.
KeepAliveTimeout - How long is an average session? By setting your
timeout high, clients benefit from a quicker response from your server
and your server uses fewer resources to service it. By setting this
too high, Apache children are tied up waiting for clients when they
could be servicing new clients.
MaxKeepAliveRequests - How many requests maximum through a keepalive
connection? If you have a site with fewer visitors at any given moment
than you have available Apache children your clients can benefit from
a high MaxKeepAliveRequests setting. Beware of greedy robots! They can
suck your server dry in a single session if this is set too high.
You can calculate your optimal setting by determining how many
requests are made per session (a "session" is an average length of
stay for your visitors). Note that this only works when the number of
clients you service at any moment is fewer than the available
Apache children. If you have more clients than available
children, KeepAlive settings will hurt overall performance and should
be turned off.
nokeepalive - Here are some broken clients known to abuse the
KeepAlive feature. You'll need to enable mod_setenvif, if it's not
already enabled or compiled in your Apache:
Send comments to the author
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
See the official Apache performance tuning documentation at:
http://httpd.apache.org/docs/misc/perf-tuning.html