Jump to content

HTTP persistent connection

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 149.125.250.233 (talk) at 20:16, 4 May 2012 (→‎Disadvantages). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

HTTP persistent connection, also called HTTP keep-alive, or HTTP connection reuse, is the idea of using the same TCP connection to send and receive multiple HTTP requests/responses, as opposed to opening a new connection for every single request/response pair.

Operation

Under HTTP 1.0, there is no official specification for how keepalive operates. It was, in essence, tacked on to an existing protocol. If the browser supports keep-alive, it adds an additional header to the request:

Connection: Keep-Alive

Then, when the server receives this request and generates a response, it also adds a header to the response:

Connection: Keep-Alive

Following this, the connection is NOT dropped, but is instead kept open. When the client sends another request, it uses the same connection. This will continue until either the client or the server decides that the conversation is over, and one of them drops the connection.

In HTTP 1.1 all connections are considered persistent unless declared otherwise.[1] The HTTP persistent connections do not use separate keepalive messages, they just allow multiple requests to use a single connection. However, the default connection timeout of Apache 2.0 httpd[2] is as little as 15 seconds[3] and for Apache 2.2 only 5 seconds.[4] The advantage of a short timeout is the ability to deliver multiple components of a web page quickly while not tying up multiple server processes or threads for too long.[5]

Advantages

According to RFC 2616 (page 46), a single-user client should not maintain more than 2 connections with any server or proxy. A proxy should use up to 2×N connections to another server or proxy, where N is the number of simultaneously active users. These guidelines are intended to improve HTTP response times, avoid congestion. If HTTP pipelining is correctly implemented, there is no performance benefit to be gained from additional connections (while additional connections may cause issues with congestion).[6]

Disadvantages

It has been suggested with modern widespread high-bandwidth connections, Keep-Alive might not be as useful as it once was. The webserver will keep a connection open for a certain number of seconds (By default 15 in Apache), which may hurt performance more than the total performance benefits. [7]

For services where single documents are regularly requested ( for example image hosting websites ), Keep-Alive can be massively detrimental to performance due to keeping unnecessary connections open for many seconds after the document was retrieved.

Keep-Alive can cause unexpected behavior if a browser is configured to use a proxy. If a browser establishes a persistent connection to a proxy, it can then send HTTP requests for different hosts over the same connection. If a rudimentary proxy then establishes a persistent connection to a remote server, it may accidentally send it HTTP requests intended for another server. [8]

Use in web browsers

Schema of multiple vs. persistent connection.

Netscape Navigator (since at least 4.05) and Internet Explorer (since at least 4.01) support persistent connections to Web servers and proxies.

Netscape does not close persistent connections using timeout. All idling persistent connections are queued. When there is a need to open new persistent connections while connecting to a different server, the idle connections are killed by the browser using some form of LRU algorithm.[9]

Internet Explorer supports persistent connections. By default, versions 6 and 7 use 2 persistent connections while version 8 uses 6.[10] Persistent connections time out after 60 seconds of inactivity which is changeable via the Windows Registry.[11]

Mozilla Firefox supports persistent connections. The number of simultaneous connections can be customized (per-server, per-proxy, total). Persistent connections time out after 115 seconds (1.92 minutes) of inactivity which is changeable via the configuration.[12]

Opera supports persistent connections since 4.0.[13] The number of simultaneous connections can be customized (per-server, total).

References

  1. ^ Persistent HTTP Connections in RFC 2616 "Hypertext Transfer Protocol -- HTTP/1.1"
  2. ^ Apache HTTP Server - KeepAlive Directive
  3. ^ Apache HTTP Server 2.0 - KeepAliveTimeout Directive
  4. ^ Apache HTTP Server 2.2 - KeepAliveTimeout Directive
  5. ^ Multiple (wiki). "Httpd/KeepAlive". Docforge. Retrieved 2010-01-30.
  6. ^ Nielssen, Henryk; Gettys, James; et al. (September 17, 1997), "Network Performance Effects of HTTP/1.1, CSS1, and PNG", Computer Communication Review, 27 (4), ISSN 0146-4833 {{citation}}: Explicit use of et al. in: |last3= (help); Unknown parameter |month= ignored (help)
  7. ^ HTTP KeepAlive Considered Harmful, 2011-01-23, retrieved 2011-09-23
  8. ^ "Tcl nano proxy server". Retrieved 4 May 2012.
  9. ^ Zhe Wang and Pei Cao (1998-12-09). "Persistent Connection Behavior of Popular Browsers". University of Wisconsin-Madison. Retrieved 2009-07-08.
  10. ^ "IE8 speeds things up". stevesouders.com. 2008-03-10. Retrieved 2009-07-17.
  11. ^ "How to change the default keep-alive time-out value in Internet Explorer". Microsoft. 2007-10-27. Retrieved 2009-07-17.
  12. ^ "Network.http.keep-alive.timeout". mozillazine.org. Retrieved 2009-07-17.
  13. ^ "Opera 4.0 Upgrades File Exchange: Includes HTTP 1.1". Opera Software. 2000-03-28. Retrieved 2009-07-08.

External links