1.1. The HTTP transaction model
- The HTTP protocol is transaction-driven. This means that each request will lead
- to one and only one response. Traditionally, a TCP connection is established
- from the client to the server, a request is sent by the client through the
- connection, the server responds, and the connection is closed. A new request
- will involve a new connection :
-
- [CON1] [REQ1] ... [RESP1] [CLO1] [CON2] [REQ2] ... [RESP2] [CLO2] ...
-
- In this mode, called the "HTTP close" mode, there are as many connection
- establishments as there are HTTP transactions. Since the connection is closed
- by the server after the response, the client does not need to know the content
- length.
-
- Due to the transactional nature of the protocol, it was possible to improve it
- to avoid closing a connection between two subsequent transactions. In this mode
- however, it is mandatory that the server indicates the content length for each
- response so that the client does not wait indefinitely. For this, a special
- header is used: "Content-length". This mode is called the "keep-alive" mode :
-
- [CON] [REQ1] ... [RESP1] [REQ2] ... [RESP2] [CLO] ...
-
- Its advantages are a reduced latency between transactions, and less processing
- power required on the server side. It is generally better than the close mode,
- but not always because the clients often limit their concurrent connections to
- a smaller value.
-
- Another improvement in the communications is the pipelining mode. It still uses
- keep-alive, but the client does not wait for the first response to send the
- second request. This is useful for fetching large number of images composing a
- page :
-
- [CON] [REQ1] [REQ2] ... [RESP1] [RESP2] [CLO] ...
-
- This can obviously have a tremendous benefit on performance because the network
- latency is eliminated between subsequent requests. Many HTTP agents do not
- correctly support pipelining since there is no way to associate a response with
- the corresponding request in HTTP. For this reason, it is mandatory for the
- server to reply in the exact same order as the requests were received.
-
- The next improvement is the multiplexed mode, as implemented in HTTP/2. This
- time, each transaction is assigned a single stream identifier, and all streams
- are multiplexed over an existing connection. Many requests can be sent in
- parallel by the client, and responses can arrive in any order since they also
- carry the stream identifier.
-
- By default HAProxy operates in keep-alive mode with regards to persistent
- connections: for each connection it processes each request and response, and
- leaves the connection idle on both sides between the end of a response and the
- start of a new request. When it receives HTTP/2 connections from a client, it
- processes all the requests in parallel and leaves the connection idling,
- waiting for new requests, just as if it was a keep-alive HTTP connection.
-
- HAProxy supports 4 connection modes :
- - keep alive : all requests and responses are processed (default)
- - tunnel : only the first request and response are processed,
- everything else is forwarded with no analysis (deprecated).
- - server close : the server-facing connection is closed after the response.
- - close : the connection is actively closed after end of response.
-
- For HTTP/2, the connection mode resembles more the "server close" mode : given
- the independence of all streams, there is currently no place to hook the idle
- server connection after a response, so it is closed after the response. HTTP/2
- is only supported for incoming connections, not on connections going to
- servers.