The first two sections of this chapterprovided a fire-hose tour of TCP connections and their performanceimplications. If you’d like to learn more about TCPnetworking, check out the resources listed at the end of the chapter.
We’re going to switch gears now and get squarelyback to HTTP. The rest of this chapter explains the HTTP technologyfor manipulating and optimizing connections. We’llstart with the HTTP Connection header, an often misunderstood butimportant part of HTTP connection management. Thenwe’ll talk about HTTP’s connectionoptimization techniques.
HTTP allows a chain of HTTPintermediaries between the client and the ultimate origin server(proxies, caches, etc.). HTTP messages are forwarded hop by hop fromthe client, through intermediary devices, to the origin server (orthe reverse).
In some cases, two adjacent HTTP applications may want to apply a setof options to their shared connection. The HTTP Connection header field has acomma-separated list of connection tokens thatspecify options for the connection that aren’tpropagated to other connections. For example, a connection that mustbe closed after sending the next message can be indicated byConnection: close.
The Connection header sometimes is confusing, because it can carrythree different types of tokens:
HTTP header field names, listing headers relevant for only thisconnection
Arbitrary token values, describing nonstandard options for thisconnection
The value
close
, indicating the persistentconnection will be closed when done
If a connection token contains the name of an HTTP header field, thatheader field contains connection-specific information and must not beforwarded. Any header fields listed in the Connection header must bedeleted before the message is forwarded. Placing a hop-by-hop headername in a Connection header is known as “protecting theheader,” because the Connection header protectsagainst accidental forwarding of the local header. An example isshown in Figure 4-9.
When an HTTP application receives a message with a Connection header,the receiver parses and applies all options requested by the sender.It then deletes the Connection header and all headers listed in theConnection header before forwarding the message to the next hop. Inaddition, there are a few hop-by-hop headers that might not be listedas values of a Connection header, but must not be proxied. Theseinclude Proxy-Authenticate, Proxy-Connection, Transfer-Encoding, andUpgrade. For more about the Connection header, see Appendix C.
TCP performance delays can add up ifthe connections are managed naively. For example, suppose you have aweb page with three embedded images. Your browser needs to issue fourHTTP transactions to display this page: one for the top-level HTMLand three for the embedded images. If each transaction requires a newconnection, the connection and slow-start delays can add up (seeFigure 4-10).[9]
In addition to the real delay imposed by serial loading, there isalso a psychological perception of slowness when a single image isloading and nothing is happening on the rest of the page. Usersprefer multiple images to load at the same time.[10]
Another disadvantage of serial loading is that some browsers areunable to display anything onscreen until enough objects are loaded,because they don’t know the sizes of the objectsuntil they are loaded, and they may need the size information todecide where to position the objects on the screen. In thissituation, the browser may be making good progress loading objectsserially, but the user may be faced with a blank white screen,unaware that any progress is being made at all.[11]
Several current and emerging techniques are available to improve HTTPconnection performance. The next several sections discuss four suchtechniques:
- Parallel connections
Concurrent HTTP requests across multiple TCP connections
- Persistent connections
Reusing TCP connections to eliminate connect/close delays
- Pipelined connections
Concurrent HTTP requests across a shared TCP connection
- Multiplexed connections
Interleaving chunks of requests and responses (experimental)
[9] For the purpose ofthis example, assume all objects are roughly the same size and arehosted from the same server, and that the DNS entry is cached,eliminating the DNS lookup time.
[10] Thisis true even if loading multiple images at the same time isslower than loading images one at a time! Usersoften perceive multiple-image loading as faster.
[11] HTMLdesigners can help eliminate this"layout delay” byexplicitly adding width and height attributes to HTML tags forembedded objects such as images. Explicitly providing the width andheight of the embedded image allows the browser to make graphicallayout decisions before it receives the objects from theserver.
Get HTTP: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.
Start your free trial