HTTP persistent connection
Encyclopedia
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.
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. 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 is as little as 15 seconds and for Apache 2.2 only 5 seconds. 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.
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. There is no HTTP performance benefit of additional connections, if HTTP pipelining over the TCP connection is correctly implemented, while significant issues with causing congestion, to the user or other users.
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.
(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.
Internet Explorer
supports persistent connections. By default, versions 6 and 7 use 2 persistent connections while version 8 uses 6. Persistent connections time out after 60 seconds of inactivity which is changeable via the Windows Registry.
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.
Opera
supports persistent connections since 4.0. The number of simultaneous connections can be customized (per-server, total).
Transmission Control Protocol
The Transmission Control Protocol is one of the core protocols of the Internet Protocol Suite. TCP is one of the two original components of the suite, complementing the Internet Protocol , and therefore the entire suite is commonly referred to as TCP/IP...
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. 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 is as little as 15 seconds and for Apache 2.2 only 5 seconds. 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.
Advantages
- Less CPU and memory usage (because fewer connections are open simultaneously)
- Enables HTTP pipeliningHTTP pipeliningHTTP pipelining is a technique in which multiple HTTP requests are sent on a single HTTP connection without waiting for the corresponding responses....
of requests and responses - Reduced network congestionNetwork congestionIn data networking and queueing theory, network congestion occurs when a link or node is carrying so much data that its quality of service deteriorates. Typical effects include queueing delay, packet loss or the blocking of new connections...
(fewer TCP connectionTransmission Control ProtocolThe Transmission Control Protocol is one of the core protocols of the Internet Protocol Suite. TCP is one of the two original components of the suite, complementing the Internet Protocol , and therefore the entire suite is commonly referred to as TCP/IP...
s) - Reduced latencyLagLag is a common word meaning to fail to keep up or to fall behind. In real-time applications, the term is used when the application fails to respond in a timely fashion to inputs...
in subsequent requests (no handshakingHandshakingIn information technology, telecommunications, and related fields, handshaking is an automated process of negotiation that dynamically sets parameters of a communications channel established between two entities before normal communication over the channel begins...
) - Errors can be reported without the penalty of closing the TCP connection
According to RFC 2616 (page 46), a single-user client should not maintain more than 2 connections with any server or proxy. A proxy
Proxy server
In computer networks, a proxy server is a server that acts as an intermediary for requests from clients seeking resources from other servers. A client connects to the proxy server, requesting some service, such as a file, connection, web page, or other resource available from a different server...
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. There is no HTTP performance benefit of additional connections, if HTTP pipelining over the TCP connection is correctly implemented, while significant issues with causing congestion, to the user or other users.
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.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.
Use in web browsers
Netscape NavigatorNetscape Navigator
Netscape Navigator was a proprietary web browser that was popular in the 1990s. It was the flagship product of the Netscape Communications Corporation and the dominant web browser in terms of usage share, although by 2002 its usage had almost disappeared...
(since at least 4.05) and Internet Explorer
Internet Explorer
Windows Internet Explorer is a series of graphical web browsers developed by Microsoft and included as part of the Microsoft Windows line of operating systems, starting in 1995. It was first released as part of the add-on package Plus! for Windows 95 that year...
(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.
Internet Explorer
Internet Explorer
Windows Internet Explorer is a series of graphical web browsers developed by Microsoft and included as part of the Microsoft Windows line of operating systems, starting in 1995. It was first released as part of the add-on package Plus! for Windows 95 that year...
supports persistent connections. By default, versions 6 and 7 use 2 persistent connections while version 8 uses 6. Persistent connections time out after 60 seconds of inactivity which is changeable via the Windows Registry.
Mozilla Firefox
Mozilla Firefox
Mozilla Firefox is a free and open source web browser descended from the Mozilla Application Suite and managed by Mozilla Corporation. , Firefox is the second most widely used browser, with approximately 25% of worldwide usage share of web browsers...
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.
Opera
Opera (web browser)
Opera is a web browser and Internet suite developed by Opera Software with over 200 million users worldwide. The browser handles common Internet-related tasks such as displaying web sites, sending and receiving e-mail messages, managing contacts, chatting on IRC, downloading files via BitTorrent,...
supports persistent connections since 4.0. The number of simultaneous connections can be customized (per-server, total).