HTTP Persistent Connections: Difference between revisions
Line 14: | Line 14: | ||
=Overview= | =Overview= | ||
By ''connection'', we understand the TCP/IP connection opened between a HTTP client and a HTTP server. Prior to the introduction of the persistent connections by HTTP/1.1, there was no official specification on how to establish and maintain persistent connections. This article assumes HTTP/1.1 and it ''does not'' apply to HTTP/1.0. | By ''connection'', we understand the TCP/IP connection opened between a HTTP client and a HTTP server. Prior to the introduction of the persistent connections by HTTP/1.1, there was no official specification on how to establish and maintain persistent connections. In most cases, a separate TCP connection was established to fetch each URL. This article assumes HTTP/1.1 and it ''does not'' apply to HTTP/1.0. | ||
Measurements of actual HTTP/1.1 connections had shown that persistent connections are preferable, for several reasons: ''resources'' (CPU time, memory, and network bandwidth) are saved on routers and hosts by opening and closing fewer TCP connections, ''network congestion'' is reduced by eliminating the packets caused by TCP open, ''latency on subsequent requests'' is reduced since there is no time spent in TCP's connection opening handshake. This last point is even more important in the case of SSL connections. | |||
=A Persistent Connection is a Point to Point Affair= | =A Persistent Connection is a Point to Point Affair= |
Revision as of 04:03, 8 January 2017
External
- RFC 2616 - Connections https://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html
- Wikipedia - Persistent Connections https://en.wikipedia.org/wiki/HTTP_persistent_connection
- HTTP Keepalive http://web.archive.org/web/20100813132504/http://www.io.com/~maus/HttpKeepAlive.html
- Akamai Support of Persistent Connections https://community.akamai.com/thread/1192
- O'Reilly HTTP: The Definitive Guide - Persistent Connections https://www.safaribooksonline.com/library/view/http-the-definitive/1565925092/ch04s05.html
Internal
Overview
By connection, we understand the TCP/IP connection opened between a HTTP client and a HTTP server. Prior to the introduction of the persistent connections by HTTP/1.1, there was no official specification on how to establish and maintain persistent connections. In most cases, a separate TCP connection was established to fetch each URL. This article assumes HTTP/1.1 and it does not apply to HTTP/1.0.
Measurements of actual HTTP/1.1 connections had shown that persistent connections are preferable, for several reasons: resources (CPU time, memory, and network bandwidth) are saved on routers and hosts by opening and closing fewer TCP connections, network congestion is reduced by eliminating the packets caused by TCP open, latency on subsequent requests is reduced since there is no time spent in TCP's connection opening handshake. This last point is even more important in the case of SSL connections.
A Persistent Connection is a Point to Point Affair
Client/Origin Server Connection
Connection via a Proxy
A HTTP persistent connection is a TCP/IP connection between the client and server that allows more that one request per connection.
It is the client that initially requests the connection to be kept alive. In HTTP 1.1, a persistent connection is initiated by specifying a "Keep-Alive" value for the "Connection" request header:
GET ... HTTP/1.1 Host: ... Connection: Keep-Alive
The server may or may not support persistent connections. If the server does support them, it will confirm that by including with the response a "Connection" response header:
200 OK Content-Length: ... Connection: Keep-Alive
Once both the client and the server have agreed on using persistent connections, they will keep the underlying TCP/IP connection open, and subsequent requests from that client will be sent over the persistent connection.
Advantages
- Both the client and the server avoid multiple TCP and SSL handshakes.
- The network throughput is increasing by avoiding TCP slowstart algorithms.
Disadvantages
- If the persistent connections are maintained for too long for idle clients, this may cause performance problems in heavily loaded servers. The higher the timeout, the more server processes will be kept occupied waiting on connections with idle clients.
Configuration
For details on how to configure HTTP persistent connections with httpd, see: