Forum Moderators: phranque
I was reading
[httpd.apache.org...] and found this line,
In some cases this has been shown to result in an almost 50% speedup in latency times for HTML documents with many images. To enable Keep-Alive connections, set KeepAlive On.
Thanks,
Aji
To illustrate, here's a non-keepalive session with the client requesting two objects:
Client: Look up IP address of server in DNS
Client: Establish TCP/IP connection to server
Client: Send HTTP request #1
Server: Serve requested resource
Server: Terminate HTTP transaction #1
Server: Terminate TCP/IP connection
Client: Look up IP address of server in DNS
Client: Establish TCP/IP connection to server
Client: Send HTTP request #2
Server: Serve requested resource
Server: Terminate HTTP transaction #2
Server: Terminate TCP/IP connection
And now again with Keep-alive:
Client: Look up IP address of server in DNS
Client: Establish TCP/IP connection to server
Client: Send HTTP request #1
Server: Serve requested resource
Server: Terminate HTTP transaction #1
Client: Send HTTP request #2
Server: Serve requested resource
Server: Terminate HTTP transaction #2
Server: Terminate TCP/IP connection
Obviously, eliminating three steps is going to make these transactions more efficient.
However, leaving the TCP/IP connection open ties it up, and precludes its use by another client (user) for whatever time remains in the Keepalive "timeout" setting. So, this setting should be adjusted to a reasonable period in order to minimize wasted connection timeout time, and to release those server threads for useful work instead.
So generally, using keepalive is good, but you don't want to "keep the connection alive" too long. How long is too long depends on the nature and size of the "typical" files retrieved from your site by a "typical" user. Never mind the details, even determining what is "typical" is difficult. So the best approach is often just to do a few trial-and-error tests, and see if you notice any improvement in page-load times and server responsiveness, while monitoring the processes to be sure you don't run out of threads for new connections. Increase the keepalive time to the point of diminishing returns, and then decrease it to minimize wasted server threads. Most benefits will be seen even with short (10-15 second) keep-alive settings, with the maximum well below one minute.
I bet you would have preferred a simple answer... ;)
Jim