Mar 19 2012
Sometimes a small constraint make you scary. Though I played around with HTTP persistence connection long back, recently when I saw this header while debugging an Azure application, I want to know what is the impact of this. There are two different opinions on using HTTP Keeps-Alive header. I want to know the impact on web apps hosted on Azure machines. What are these opinions and what happened on Azure machines?
Before that, let us see what is HTTP Keeps-Alive and how it works in HTTP 1.1. See the below figure.
When a client made a request to server with the header “Connection: Keep-Alive”, the server (here IIS 7.0) create a connection object for handling a request. Once the response has sent, instead of closing the connection object, IIS keeps that because of the Keep-Alive instruction from client. IIS also sends Keep-Alive header as part of the response means it is fine with HTTP Keep-Alive. The connection object is alive for 2 minutes. Within this period, if any other request from the same client comes, it reuses the same connection object for the request and also extens the timeout for next 2 minutes. This will improves the responsiveness of your applications. In the above figure, the numbers of actual clock time (hh:mm:ss:mss) the measurements taken. IIS team recommends to use this. So, what is the improvement?
Let us see various end-to-end response time for with and without Keep-Alive options for 4 GET requests:
The results show no major difference with or without having HTTP Keep-Alive option. I’ve tried to give high stress to the system to find out the behavior changes in the server with or without HTTP Keep-Alive option. Unfortunately, even I’ve unchecked the option, it sill works on Azure machines.
So, what I came to know is that using HTTP Keep-Alive neither make significant improvement nor lower the responsiveness. Now, let us come to the main point for the purpose this post.
In the *nix world, people are not recommending to use this option. In Apache, even if it is enabled, the time out period is 15 seconds in contrast with 2 minutes in IIS. Surprisingly, Nginx’s default time out is 75 seconds. The only problem most of the *nix people mentioned that, if your application has more number of resources (html + css + images) per single request, this is worth. However, it is a 1:1, avoid it. Keeping open connection on server costs high resource consumption in memory.
Is that make sense? I think this is not applicable for IIS and Azure.