Wednesday, August 17, 2011

KeepAlive Feature in Apache

KeepAlive is the feature that allow use existing connection for new requests. In the case of web server Keep Alive HTTP Persistent connections are being used . We can understand by following example

root#curl -v

Two request are made for but only one connection will serve the purpose. Connection created when first request made and next request will travel on existing connection which made for serving first request.

Now let us discuss Keep Alive feature from Apache Web server perspective. The benefit of having Keep Alive on that the client will be able to request more than one entity from web server without having to create another TCP connection. The problem with this is that if you have a connection limit in Apache set to 300 and there is 300 active connections all others have to wait until first 300 client either done or reach keep-alive timeout.

Disabling Keep-Alive force client to create one connection per request. On the low memory servers it is advisable to turn Keep-Alive feature off.

The biggest argument against Keep Alive in Apache is that it block Apache processes with supportive fact that the client using Keep Alive prevent his apache process to serve other client until connection either closed or time out. In the same span of time more client could be served by same apache process. One strong recommendation is, use two instances of Apache one for dynamic content with mod_php(if dynamic pages are coded in PHP) and other for static content. Keep Keep Alive off for Instance which serve dynamic pages and turn on Keep Alive Instance serving static pages.