Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Keep Alive in a large Web Applications

I have a web application deployed over IIS 7.0. the application is accessible by large number of users and manipulates large data ..my question is concerning the HTTP Keep-Alive option which is set to true by default.

is it a better approach to set the HTTP Keep-Alive to false or true.

in case of true is the good approach to use time out?

like image 597
Saber Shebly Avatar asked May 24 '11 07:05

Saber Shebly


People also ask

How do I keep my HTTP connection alive?

Keep-Alive is enabled by explicitly requesting it via HTTP header. If you don't have access to your web server configuration file, you can add HTTP headers yourself by using . htaccess file.

What is the purpose of Keep-Alive in HTTP?

The HTTP keep-alive header maintains a connection between a client and your server, reducing the time needed to serve files. A persistent connection also reduces the number of TCP and SSL/TLS connection requests, leading to a drop in round trip time (RTT).

Does HTTP 1.0 support Keep-Alive?

Keep-alive connections are enabled by default in HTTP/1.1 while not in HTTP/1.0.

How does HTTP persistent connection work?

HTTP has a persistent connection function that allows the channel to remain open rather than be closed after a requested exchange of data. TCP is a connection-oriented protocol: It starts a connection after confirmation from both ends that they are available and open to a data exchange.


2 Answers

KeepAlive should normally be used to handle the requests that immediately follow an HTML request. Let's say on the first visit to your site I get an HTML page with 5 css, 5js and 25 images, I will use my HTTP connection which is still alive to request these things (well, depends on the browser, I'll maybe use 3 connection to speed up these things).

To handle this fact we usually use a Keepalive of 2s or 3s. Having a longer keepalive means the connection is waiting for the next page that the user may request. This may be a valid way of thinking, next time the user will want a page, we'll avoid to loose time establishing HTTP connection (and this can be the longest part of the request/response time). But for your server that mean most of HTTP connection that are handled by the server are doing... nothing. And you will reach your MaxConnection (W3SVC/MaxConnections with a ridiculous default to 10), with connections doing nothing. Really Bad. So long keep-alive needs big webservers and should be used only if your application really needs it.

If you use Keepalive in a 'classical website' you must change the connection timeout (by default 2min). In Apache you would have 2 settings, a keepalive tiemout (5s by default) and a connection timeout (2min). In IIS seems the timeout settings is used for both. So do not set it to 2s (a client really slow in sending his request will timeout), but something like 10s is maybe enough. Now one response is to disallow Keep-Alive, and make the browser opening more connections. Another response is to use a modern webserver (like nginx or cherokee for example) which handles keep-alive connection in a more elegant and resource-free way than Apache or IIS.

Even if you do not use Keepalive, what's the reason of waiting 2 minutes for a client timeout? it's is certainly too high, decrease this value to something like 60s.

Then you should check several settings related to timeout (ConnectionTimeout, HeaderWaitTimeout, MinFileBytesPerSec) and this nice response on performances settings in the registry.

like image 154
regilero Avatar answered Nov 10 '22 00:11

regilero


This article will bring more insight and don't forget to check the "How do we fix it?" section http://mocko.org.uk/b/2011/01/23/http-keepalive-considered-harmful/

like image 32
Numan Avatar answered Nov 09 '22 22:11

Numan