Saturday, 6 October 2012

keep alive connections

HTTP 1.1 introduced keep alive connections and request pipe lining . In HTTP 1.0 every connection was closed after response is served to user , so for every new request , user has to establish connection with server and then send the request . In keep alive connections , server keep the connection alive for a specific time which is called keep alive timeout . So the socket connection which is created by server , will be active for keep alive time out period . If this keep alive timeout expires , then server closes this connection.

Http Header which is used for this is Connection : Keep-Alive . So, keep alive connection is very efficient because client does not need to establish the connection every time .In server if a worker thread is assigned to each connection , then this thread will be busy for keep alive time out period , even if there is not activity by client . so , we can not set keep alive time out value to a large number . for example server is configured like this :
worker thread : 100
keep alive connections :100
keep alive time out : 60 seconds

when a user sends a request , server creates a connection and assigns a worker thread. But after sending one request , user don't send next requests , this thread will be idle in server , waiting for next keep alive request for 60 seconds .