Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pros and Cons of Keep-Alive from Web Server Side

Keep-Alive connection feature in HTTP protocol is meant to reduce TCP connection hits to web server. It should be able to improve web server performance. However, I found that some web servers deliberately disable KeepAlive feature from server side.

In my understanding, some reverse proxy, i.e. HAProxy, disables HTTP keep-alive in order to reduce memory usage which is more critical than CPU usage in some situation.

Is there any other reason why Web server disables Keep-Alive?

like image 597
Morgan Cheng Avatar asked Aug 09 '10 14:08

Morgan Cheng


People also ask

Should I Enable keep alive?

Enabling Keep-Alive is a great way to optimize your website as it helps improve speed and performance, ensuring faster load times and higher efficiency. By turning the Keep-Alive header on, the client and server can reuse a single TCP connection for a number of requests and responses.

How long does connection keep alive last?

It sets how long your server should wait for new requests from clients. A value between 7 to 10 seconds is usually ideal. With higher traffic this value can go extremely higher to make sure there is no frequent TCP connection re-initiated.

What is the purpose of keep alive message?

A keepalive (KA) is a message sent by one device to another to check that the link between the two is operating, or to prevent the link from being broken.

Is HTTP keep-alive default?

Keep-alive connections are enabled by default in HTTP/1.1 while not in HTTP/1.0. HTTP/1.0 was designed to close the connection after every request between client and server. We can actually check this difference using telnet .


1 Answers

Actually, Keep-Alive is meant to improve HTTP performance, not server performance (though for SSL connections it does reduce the cost on the server of re-negotiating the encryption). The big win is in the number of round trips the browser has to make to get the content. With Keep-Alive the browser gets to eliminate a full round trip for every request after the first, usually cutting full page load times in half.

Keep-Alive increase server load which is why some shared hosting providers disable it. Each open connection consumes memory as well as a file descriptor (linux) and in extreme cases (some Apache configs) it may have a 1:1 mapping from connections to processes.

like image 132
pmeenan Avatar answered Oct 21 '22 14:10

pmeenan