Home > Persistent Connections and HTTP
Persistent Connections and HTTP
Persistent connections are used by all modern browsers to ensure that Web clients are able to make the most efficient use of the network between them and the server, especially over slow connections. The use of persistent connections help improve the overall speed of the perceived download by eliminating the costly overhead of opening and closing a new TCP connection for every object downloaded by the browser.
The benefits in network efficiency should be seen immediately. When a new TCP connection is opened, the Three-Way TCP Handshake must be performed, allowing the client and the server to agree on some mutual aspects of the connection between them. However, when this process is required for every object download, this diplomatic nicety adds a substantial amount of overhead retrieving the requested page and its associated objects. Not only does a new connection have to be opened correctly, but it must be closed correctly after all of the data is transferred. This additional group of "empty" packets — packets containing no data, but necessary for the maintenance of the connection — impedes the efficient flow of data between the client and the server.
Persistent connections do not come without some penalties, and these performance concepts must be considered when configuring a servere to respond to clients using persistent connections.
Persistent Connection Timeouts
When the idea of persistent HTTP connections was designed, and later codified in HTTP/1.1, there was one very important definition that was excluded: the length of time that a client or a server had to maintain the persistence of an open connection if no data was flowing across it. This oversight leads to a problem when the transfer of data is complete between the client and the server — when does the connection close and who closes it?
The issue of persistent connection maintenance is vital in a high performance environment, as a server that is maintaining state on a large number of "dead" connections is wasting resources that could be applied to incoming requests from new visitors.
Client applications have their own timeout values for persistent connections, but the minimum value found in the browsers examined for this article was 60 seconds. For a high-traffic Web server, maintaining state on a TCP connection for this length of time is a severe drain on scarce resources. On the Web servers I manage, I have set the server-side keep-alive timeout to 10 seconds. This means that the connection is only maintained for 10 seconds after the last packet is sent.
The default timeout value for persistent connection timeouts varies from Web server to Web server. In Apache, connections are kept open for 15 seconds after all the previous data has been sent; in IIS, this value is 900 seconds. Which one is correct?
The answer is: it depends. It depends on whether the server is responsible for serving a large number of small objects as quickly as possible to as many clients as possible, or if it is running a large web-based application or Web service that relies on ongoing data transfers that benefit from persistence.
With this is in mind, adjust Keep-Alive or persistence timeouts according to the particular client base of the server and the role it plays in an organization.
Proxy Servers and Persistent Connections
The external interfaces of most proxy servers do not maintain persistence for two reasons.
Be aware that any clients that visit a site through a proxy server are most likely not going to use persistent connections. However, by making Web site page components more cache-friendly, performance improvements for these clients can be gained in other ways.
Persistent connections are an important way to ensure that the performance of a Web site meets or exceeds the expected values. However, it is vital to be aware of the potential pitfalls the can occur when implementing persistent connections with the default values, or on sites with large numbers of customers visiting from behind proxy servers.