Keeping The Connections Open... HTTP Keep-Alives Print E-mail
Written by Leon Ruumpol source: Microsoft Operations, Monday, 14 August 2006

HTTP Keep-Alives continues to be one of the most misunderstood settings in IIS.  This particular setting can have huge performance implications on your web site; take for example a typical browser that requests content from a web page. Without HTTP Keep-Alives enabled on the web server, each request for an element on that page, such as an image will require a separate connection from the client.  The server in turn must use its resources to process each of these additional connections.  This means that the server must go through the whole TCP-Handshake process for each connection. For those of you that don’t entirely remember what that means here is a brief explanation:

The client machine sends a TCP SYN (Synchronize)

The Server receives the SYN and sends a SYN of its own.  The server also follows with an ACK (Acknowledgement).  This happens in the same TCP packet and is often referred to as SYN-ACK.  The Acknowledge informs the client that the server has received its data and it’s expecting the next segment of data bytes to be sent.

The Client machine receives the SYN-ACK and sends an ACK.

Only after this handshake has taken place can data be transferred.  Both the client machine and server must maintain the port numbers and the sequence numbers used for each connection.

In IIS 6.0 HTTP Keep-Alives are enabled by default, IIS will hold an inactive connection open for as long as the ConnectionTimeout value, which by default is 120 seconds.  Not having to handle the extra connections required to download multiple elements from a web page increases the server’s overall efficiency.

REQUEST: **************\nGET /windows/default.mspx HTTP/1.1\r\n

Host: www.microsoft.com\r\n

Accept: */*\r\n

\r\n

 

RESPONSE: **************\nHTTP/1.1 200 OK\r\n

Connection: Keep-Alive\r\n

Content-Length: 30008\r\n

Date: Wed, 02 Aug 2006 22:49:09 GMT\r\n

Content-Type: text/html; charset=iso-8859-1\r\n

Server: Microsoft-IIS/6.0\r\n

X-Powered-By: ASP.NET\r\n

X-AspNet-Version: 2.0.50727\r\n

Last-Modified: Wed, 02 Aug 2006 20:58:17 GMT\r\n

 

ITEMS *******************

HTTP Status        URI

200          www.microsoft.com               /windows/default.mspx                        

                200          www.microsoft.com               /windows/default.mspx                        

                200          www.microsoft.com                /Windows/mnp_utility.mspx/templatecss?template=%2fbusiness%2fomniture%2ftemplates%2fMNP2.GenericHome&shell=%2fwindows%2fConfiguration.xml&locale=en-us      

                200          www.microsoft.com               /Windows/mnp_utility.mspx/menujs?mnpshell=%2fwindows%2fConfiguration.xml&clicktrax=True               

                200          www.microsoft.com               /library/mnp/2/aspx/css.aspx?locale=en-us&name=Menu&static=Page          1,685      

                200          www.microsoft.com               /library/mnp/2/aspx/js.aspx?&path=/library/include/ctredir.js&name=Menu                   

                200          www.microsoft.com               /library/toolbar/3.0/css.aspx?c=/windows/Configuration.xml

                200          www.microsoft.com               /library/toolbar/3.0/quicklinks/ql.js                     

                200          www.microsoft.com               /library/mnp/2/gif/ql.gif                         

                200          www.microsoft.com               /library/toolbar/3.0/images/banners/windows_masthead_ltr.gif      

                200          www.microsoft.com               /library/mnp/2/gif/arrowLTR.gif           

                200          www.microsoft.com               /windows/shared/js/s_code.js            

                200          www.microsoft.com               /library/media/1033/windows/images/homepage/IE7_Small_ad_e.jpg

                200          www.microsoft.com               /library/media/1033/windows/images/homepage/65349_hero_393x220_Vista.jpg                        

                200          www.microsoft.com               /library/media/1033/windows/images/homepage/green_arrow.jpg                 

                200          www.microsoft.com               /library/media/1033/windows/images/homepage/player_55x55.gif                 

                200          www.microsoft.com               /library/media/1033/windows/images/homepage/62277_55x55_spyware_F.jpg                            

                200          www.microsoft.com               /windows/images/homepage/products/winFamLogo_XP.gif                          

                200          www.microsoft.com               /Windows/images/homepage/products/component_divider.gif     

                200          www.microsoft.com               /windows/images/homepage/products/winFamLogo_prod_hdr.gif                               

                200          www.microsoft.com               /windows/images/homepage/products/55506_134x14_WFnav_wss.gif                        

                200          www.microsoft.com               /windows/images/homepage/products/55506_119x14_WFnav_wemb.gif                     

                200          www.microsoft.com               /windows/images/homepage/products/55506_101x14_WFnav_wm.gif                         

                200          www.microsoft.com               /windows/images/homepage/products/55506_116x14_WFnav_vpc.gif                         

                200          www.microsoft.com               /windows/images/homepage/products/winFamLogo_tech_hdr.gif                

                200          www.microsoft.com               /windows/images/homepage/products/55506_112x14_WFnav_mdx.gif                        

                200          www.microsoft.com               /windows/images/homepage/products/55506_150x14_WFnav_ie.gif                            

                200          www.microsoft.com               /windows/images/homepage/products/55506_131x14_WFnav_wmp.gif                       

                200          www.microsoft.com               /windows/images/homepage/products/55506_150x14_WFnav_wds.gif                        

                200          www.microsoft.com               /windows/images/homepage/products/winFamLogo_relsites_hdr.gif                           

                200          www.microsoft.com                /library/toolbar/3.0/text.aspx?t=TQ%3d%3d&f=FFFFFF&b=6487DB&font=Microsoft+Logo+95%2c+13pt&w=105&h=29&a=0&l=0&v=0&c=DeMqBqiN3ORi7XLcgI%2fvxqO1OI4%3d

                200          www.microsoft.com               /favicon.ico           

 

As you can see in the response from above the server responds back with

Connection: Keep-Alive\r\n

That means that Keep-Alive is enabled on the servers.

 

There were a total of 32 different GET requests for items on www.microsoft.com, each of these requests were using the same TCP connection.  One caveat to this is if a request calls a different hostname, that request will happen over a different TCP connection. 

 

What’s the performance with or without Keep-Alives enabled?

 

Using Keynote Systems (www.keynote.com) to measure the load time of the web page from an agent located in Hong Kong, I get the following data:

 

With Keep-Alives:

Total page load time:5.34

 

Without Keep-Alives:

Total page load time:8.89

 

The increased latency is due primarily to the setup of the initial connection.

 

Why would you disable Keep-Alives?

 

Disabling Keep Alives will cause the server to ignore a client request to keep the connection open.  Some sites may just serve a single URI for example. http://../foo.gif ; in this case there is no need to keep the connection open due to the fact that only this particular resource is being called.  You may get better performance because the connection is not left opened for x amount of time.  The general rule is; disable HTTP Keep-Alives only after you have a clear understanding of how it affects the performance of your site.
Comments
Add NewSearchRSS
Only registered users can write comments!
 
< Prev   Next >