§2.2.1–2.2.2The Web and HTTP · Non-Persistent and Persistent Connections

Application layer Kurose & Ross pp. 95–100 · ~20 min read

  • web page
  • object
  • uniform resource locator
  • hostname
  • browser
  • web server
  • stateless protocol
  • non-persistent connection
  • persistent connection
  • round-trip time
  • pipelining

Where you are

  • Application layer you are here
  • Transport layer
  • Network layer
  • Link layer
  • Physical layer

HTTP (HyperText Transfer Protocol) is a simple, stateless, plain-text protocol, and almost all of the time it takes to load a page is spent waiting for round trips rather than moving bytes.

Words you will meet

  • Web page — a document made of several files that a browser shows as one page.
  • Object — one file, with its own web address.
  • URL — Uniform Resource Locator: which server has a file, and where on that server.
  • Stateless protocol — one whose server remembers nothing about earlier requests.
  • Non-persistent connection — a new TCP (Transmission Control Protocol) connection per object, closed straight after.
  • Persistent connection — one connection kept open and reused.
  • RTT — round-trip time: how long a small packet takes to go there and back.
  • Pipelining — sending the next request without waiting for the previous answer.

Why this matters

HTTP (HyperText Transfer Protocol) is the protocol you will meet most often, and it is deliberately the first one this book studies in detail, because it is straightforward and easy to understand.

But the real content of this section is a piece of engineering that recurs everywhere: the cost of setting up a connection. Section 2.2.6 rebuilds HTTP around it. Chapter 3 explains where the handshake comes from. Section 3.8 introduces QUIC (Quick UDP Internet Connections) , a protocol whose main selling point is making that cost smaller still.

What HTTP is

Until the early 1990s the Internet was used mainly by researchers and students, to log in to remote hosts, transfer files, and send news and e-mail. Then the World Wide Web arrived. It was the first Internet application that caught the general public’s eye. It turned the Internet from one of many data networks into essentially the one and only data network.

What appeals most is that the Web operates on demand. Users receive what they want, when they want it — unlike broadcast radio and television, which force users to tune in when the content provider chooses.

Pages, objects and URLs

Some vocabulary first, because the rest of the section depends on it.

A web page , also called a document, consists of objects . An object is simply a file — an HTML (HyperText Markup Language) file, a JPEG (Joint Photographic Experts Group) image, a JavaScript file, a CSS (Cascading Style Sheets) style sheet, a video clip.

What makes a file an object is that it is addressable by a single URL (Uniform Resource Locator) .

Count the base file

If a web page contains HTML text and five JPEG images, the page has six objects: the base HTML file plus the five images. The base HTML file references the others by their URLs.

Getting this count right matters, because every calculation in this section multiplies by it.

Each URL has two components: the hostname of the server that houses the object, and the object’s path name.

http://www.someSchool.edu/someDepartment/picture.gifhostnamewhich server has it§2.4 turns this into an addresspath namewhere on that serverthis is what the GET request carriesEvery object in a page has one of these. A page of six objects has six URLs.

Because web browsers implement the client side of HTTP, in the context of the Web the words browser and client are used interchangeably. Web servers implement the server side and house the objects. Popular ones include Apache and Microsoft Internet Information Server.

Request and response

HTTP is implemented in two programs, a client and a server, executing on different end systems and talking by exchanging HTTP messages. HTTP defines the structure of those messages and how the two sides exchange them.

Server runningApache web serverHTTP requestHTTP responseHTTP requestHTTP responsePC runninga browserSmartphone runninga browserFigure 2.6

HTTP uses TCP (Transmission Control Protocol) as its underlying transport protocol, not UDP (User Datagram Protocol) . The client first initiates a TCP connection. Once it is established, the browser and server processes reach TCP through their sockets. The client sends request messages into its socket and receives responses from it; the server does the mirror image.

In plain words — why layering earns its keep here

Once the client pushes a message into its socket, the message is out of the client’s hands and in the hands of TCP. And section 2.1.4 told you TCP provides reliable data transfer.

So every HTTP request eventually arrives intact at the server, and every response arrives intact at the client. HTTP need not worry about lost data, or about how TCP recovers from loss or reordering. That is the job of TCP and the layers below it.

This is a great advantage of a layered architecture, and it is worth noticing how much shorter it makes the HTTP specification.

HTTP is stateless

The server sends requested files to clients without storing any state information about the client. If a client asks for the same object twice within a few seconds, the server does not say that it just served that object. It resends the object, having completely forgotten what it did earlier.

Because an HTTP server maintains no information about its clients, HTTP is called a stateless protocol .

That sounds like a weakness. It is a deliberate strength: it is what has allowed engineers to develop high-performance web servers that handle thousands of simultaneous TCP connections. Section 2.2.4 shows how cookies put state back on top when an application genuinely needs it.

Which version

Each version of the protocol is defined by its own RFC (Request For Comments) .

VersionRFCStatus
HTTP/1.0 RFC (Request For Comments) 1945The original, from the early 1990s. Uses non-persistent connections.
HTTP/1.1RFC 7230As of 2020, the majority of HTTP transactions. Persistent connections with pipelining by default.
HTTP/2RFC 7540Increasingly supported by browsers and servers. Section 2.2.6 covers it.

What a connection costs

In many Internet applications the client and server communicate for an extended period, with the client making a series of requests. The developer faces a decision: should each request/response pair go over a separate TCP connection, or should all of them share one?

The first is a non-persistent connection ; the second is a persistent connection . HTTP can use either. It uses persistent connections in its default mode, but clients and servers can be configured otherwise.

Non-persistent, step by step

Suppose a page consists of a base HTML file and 10 JPEG images, all on the same server, and the base file’s URL is http://www.someSchool.edu/someDepartment/home.index. Here is what happens:

  1. The HTTP client process initiates a TCP connection to www.someSchool.edu on port 80, the default port for HTTP. A socket is created at the client and one at the server.
  2. The client sends an HTTP request message via its socket, including the path name /someDepartment/home.index.
  3. The server process receives the request and retrieves the object from its storage — its memory or its disk. It puts the object in an HTTP response message and sends it via its socket.
  4. The server tells TCP to close the connection. TCP does not actually terminate until it knows the client received the response intact.
  5. The client receives the response and the connection terminates. The message says the object is an HTML file. The client extracts it, examines it, and finds references to the 10 JPEG objects.
  6. Steps 1–4 repeat for each of those 10 objects.

Each non-persistent connection transports exactly one request message and one response message. So when a user requests this page, 11 TCP connections are generated.

What HTTP does not decide

As the browser receives the page, it displays it. Two different browsers may display the same page somewhat differently. HTTP has nothing to do with how a page is interpreted. The specifications define only the communication between the client program and the server program.

The back-of-the-envelope calculation

How long does one object take? Define the round-trip time ( RTT (Round-Trip Time) ): the time for a small packet to travel from client to server and back. It includes propagation delays, queuing delays in intermediate routers and switches, and processing delays — all of them from section 1.4.

Figure 2.7 — the cost of one object over a non-persistent connection
message 4 of 4
0 ms90 ms180 ms270 ms360 msLin’s laptop192.168.1.24Timewww.example.edu198.51.100.7:80TimeRTT 1 complete — connection open, nothing asked for yetRTT 2 complete — file begins to arriveSYN — initiate TCP connectionSYN, ACKACK + GET /index.htmlHTTP/1.1 200 OK + index.html

Click any arrow to see what that message says and why it is sent.

Click any arrow to see what it carries. Two round trips pass before a single byte of the file moves.

Read this diagram as text
  1. Lin’s laptop sends SYN — initiate TCP connection to www.example.edu. Part 1 of the three-way handshake. A small TCP segment carrying no application data at all. The browser has not yet said what it wants.
  2. www.example.edu sends SYN, ACK to Lin’s laptop. Part 2. The server agrees. These first two parts together take exactly one RTT — the first of the two the book counts.
  3. Lin’s laptop sends ACK + GET /index.html to www.example.edu. Part 3 of the handshake and the HTTP request travel together. This is why the total is two RTTs and not two and a half: the acknowledgement was going to be sent anyway, so the request rides along for free.
  4. www.example.edu sends HTTP/1.1 200 OK + index.html to Lin’s laptop. The second RTT completes as the response arrives. Only now do the file’s bits start to move. Pushing 100 kB into a 100 Mbps link takes a further 8.00 ms — small next to a 180 ms round trip, which is the whole point of this section.

Lifelines, left to right: Lin’s laptop (host), www.example.edu (server).

Opening the connection involves a three-way handshake. The client sends a small TCP segment; the server acknowledges and responds with a small segment; the client acknowledges back. The first two parts take one RTT.

Then something neat happens. After the first two parts, the client sends the HTTP request message combined with the third part of the handshake — the acknowledgement it was going to send anyway. Once the request arrives, the server sends the file. That request/response consumes another RTT.

The book’s result

Thus, roughly, the total response time is two RTTs plus the transmission time at the server of the HTML file.

Persistent connections

Non-persistent connections have two shortcomings.

First, a brand-new connection must be established and maintained for each requested object. For each connection, TCP buffers must be allocated and TCP variables kept in both the client and the server. That is a significant burden on a web server serving hundreds of clients at once.

Second, each object suffers a delivery delay of two RTTs — one to establish the connection, one to request and receive.

With HTTP/1.1 persistent connections the server leaves the connection open after sending a response. Subsequent requests and responses between the same client and server travel over the same connection. An entire web page can be sent over one connection, and so can several pages from the same server. Typically the server closes a connection when it has not been used for a configurable timeout interval.

Requests can also be made back-to-back, without waiting for replies to pending requests. That is pipelining , and it is part of HTTP/1.1’s default mode.

Non-persistent: every object pays the full price again
message 8 of 8
0 ms180 ms360 ms540 ms720 msLin’s laptopTimewww.example.eduTimeobject 1 of 4 done — connection closedobject 2 of 4 done — and two more to goSYNSYN, ACKACK + GET /index.htmlindex.html (100 kB)SYNSYN, ACKACK + GET /style.cssstyle.css (12 kB)

Click any arrow to see what that message says and why it is sent.

The base file, then the first of three referenced objects. Watch the pattern repeat: open, ask, receive, close. Two more objects follow, identically.

Read this diagram as text
  1. Lin’s laptop sends SYN to www.example.edu. Connection 1 of 4 opens.
  2. www.example.edu sends SYN, ACK to Lin’s laptop.
  3. Lin’s laptop sends ACK + GET /index.html to www.example.edu.
  4. www.example.edu sends index.html (100 kB) to Lin’s laptop. The base file arrives after 2 RTT = 360 ms. The server now closes the connection. Everything just spent is spent again for the next object.
  5. Lin’s laptop sends SYN to www.example.edu. Connection 2 of 4. A brand-new connection must be established and maintained for each requested object. TCP buffers are allocated and TCP variables kept, at both ends, all over again.
  6. www.example.edu sends SYN, ACK to Lin’s laptop.
  7. Lin’s laptop sends ACK + GET /style.css to www.example.edu.
  8. www.example.edu sends style.css (12 kB) to Lin’s laptop. A 12 kB file takes 0.96 ms to transmit. It cost 360 ms to fetch. The file itself is almost free; the waiting is everything.

Lifelines, left to right: Lin’s laptop (host), www.example.edu (server).

Persistent with pipelining: one connection, one extra round trip
message 10 of 10
0 ms138 ms276 ms414 ms552 msLin’s laptopTimewww.example.eduTimebase file in — the other three URLs are now knownwhole page in, after 3 RTTSYNSYN, ACKACK + GET /index.htmlindex.html (100 kB)GET /style.cssGET /logo.pngGET /app.jsstyle.css (12 kB)logo.png (40 kB)app.js (220 kB)

Click any arrow to see what that message says and why it is sent.

The same four objects. The three requests go back-to-back without waiting, and the three objects come back the same way.

Read this diagram as text
  1. Lin’s laptop sends SYN to www.example.edu.
  2. www.example.edu sends SYN, ACK to Lin’s laptop.
  3. Lin’s laptop sends ACK + GET /index.html to www.example.edu.
  4. www.example.edu sends index.html (100 kB) to Lin’s laptop. Two RTTs, exactly as before. Nothing is saved on the base file — it is the *only* object whose URL the browser knew in advance.
  5. Lin’s laptop sends GET /style.css to www.example.edu. The browser has now read the HTML and knows the other three URLs. It sends all three requests back-to-back, without waiting for any reply. That is pipelining.
  6. Lin’s laptop sends GET /logo.png to www.example.edu.
  7. Lin’s laptop sends GET /app.js to www.example.edu.
  8. www.example.edu sends style.css (12 kB) to Lin’s laptop. The server received the back-to-back requests, so it sends the objects back-to-back.
  9. www.example.edu sends logo.png (40 kB) to Lin’s laptop.
  10. www.example.edu sends app.js (220 kB) to Lin’s laptop. All four objects are in, after 3 RTT plus 29.76 ms of transmission — 569.76 ms against 1,469.76 ms for the non-persistent case. The connection stays open in case more is wanted.

Lifelines, left to right: Lin’s laptop (host), www.example.edu (server).

Pipelining costs three round trips, not two

It is tempting to say that with one connection and pipelining the whole page costs 2 RTT. It does not, and the reason is worth holding on to.

The browser cannot ask for the referenced objects until it has read the base HTML file, because that file is where their URLs are written. So:

  • 1 RTT to open the connection;
  • 1 RTT to request and receive the base file — the book’s two-RTT result;
  • 1 RTT for all the remaining objects together, pipelined.

Three round trips for a four-object page. Also three for a forty-object page. The object count has dropped out of the round-trip term entirely, and that is the gain.

A page with only one object is the exception: there is nothing to pipeline, so it costs the book’s 2 RTT exactly. Try objects = 1 in the calculator below.

Put numbers on it

How long does Lin’s page take?

What each symbol means

  • nobjects in the page, counting the base HTML file ()
  • Ltotal size of the page (bytes)
  • Rlink rate of the bottleneck link (bits/s)
  • RTTround-trip time to the server (s)
  • pparallel connections the browser opens ()

Read aloud: Every object fetched over its own connection costs two round trips; keeping one connection open and asking for everything at once costs three round trips in total, no matter how many objects there are.

Non-persistent, one at a time1.47 s

each object costs 2 RTT: one to open the connection, one to ask and receive
4 objects x 2 x 180 ms = 1.44 s
transmission = 2,976,000 bits / 100 Mbps = 29.8 ms
total = 1.44 s + 29.8 ms = 1.47 s

Persistent, no pipelining930 ms

the connection is opened once: 180 ms
then one RTT per object, because each request waits for the last reply
4 x 180 ms = 720 ms
transmission = 29.8 ms
total = 180 ms + 720 ms + 29.8 ms = 930 ms

Non-persistent, parallel750 ms

the base file must arrive first — the browser cannot know the other URLs until it does
base file: 2 x 180 ms = 360 ms
remaining 3 objects, 3 at a time = ceil(3 / 3) = 1 round(s)
1 x 2 x 180 ms = 360 ms
transmission = 29.8 ms  (unchanged — the same bits cross the same link)
total = 720 ms + 29.8 ms = 750 ms

Persistent + pipelining (HTTP/1.1 default)570 ms

one RTT to open the connection: 180 ms
one RTT to request and receive the base file: 180 ms
only now does the browser know the other 3 URLs
one more RTT for all 3 of them: the requests go back-to-back,
  without waiting for replies, and the objects come back back-to-back
transmission = 29.8 ms
total = 3 x 180 ms + 29.8 ms = 570 ms
the object count has dropped out of the RTT term — 3 objects or 300, still 3 RTT

Change any number above and the arithmetic re-runs, carrying the units through.

The defaults are the running example: Lin’s 372 kB page over a 100 Mbps access link, 180 ms to Frankfurt. Drag RTT down to 20 ms and watch the four answers collapse together — the round trips are the whole story only while the link is fast and the server is far away.

Worked example — Lin’s page from Bangkok

Lin’s laptop loads www.example.edu: a 372 kB page in four objects, over a 100 Mbps access link, 180 ms round-trip to Frankfurt.

Transmission time for the whole page is 2,976,000 bits ÷ 100 Mbps = 29.76 ms. Every strategy below moves exactly those bits over exactly that link, so that 29.76 ms is common to all of them. Everything else is waiting.

StrategyRound tripsTotal
Non-persistent, one object at a time81,469.8 ms
Persistent, no pipelining5929.8 ms
Non-persistent, 3 in parallel4749.8 ms
Persistent + pipelining3569.8 ms

The page loads 2.58× faster, and not one byte of it changed. The time was never in the file; it was in the waiting.

Notice also that the transmission time is 2 % of the fastest total. Doubling Lin’s link rate to 200 Mbps would save 14.88 ms out of 569.76 — under 3 %. Removing one round trip saves 180 ms. This is why the rest of §2.2 is about round trips and not about link rates.

Non-persistent and persistent connections
Non-persistentHTTP/1.0PersistentHTTP/1.1 default
Connections for an n-object page
Round trips (n = 4)
Burden on the server
Pipelining possible?
When does the connection close?
What browsers do about it

Cells marked ⓘ have a reason behind them — click to read it.

Click any ⓘ for the reasoning behind the cell.

Parallel connections

The six steps above were deliberately vague about one thing: whether the client fetches the 10 JPEGs over 10 serial connections, or some of them in parallel. Users can configure some browsers to control the degree of parallelism. Browsers may open multiple TCP connections and request different parts of the page over each.

As chapter 3 will show, parallel connections shorten the response time — the calculator above lets you watch that happen. Section 2.2.6 returns to the practice and shows that browsers have a second, less innocent motive for it.

Check yourself

Check yourself

0 of 6 answered
  1. 1.A web page contains HTML text and five JPEG images. How many objects is that, and how many TCP connections does HTTP/1.0 use to fetch it?

  2. 2.Why does one object over a non-persistent connection cost two RTTs rather than one?

    Count what happens before any HTML is asked for.

  3. 3.predictIn the calculator, set the page to 4 objects and RTT to 180 ms. Persistent-with-pipelining costs 3 RTT. Why not 2, since the connection is opened only once?

    What does the browser know at the moment the connection opens?

  4. 4.Which change makes the largest difference to how long Lin's four-object page takes: opening the same number of connections in parallel, or keeping one connection open and pipelining on it?

  5. 5.An HTTP server has just sent you an object. Ten seconds later you ask for exactly the same object. What does the server do?

  6. 6.Browsers may open several parallel TCP connections to one server. Given that the section shows this speeds a page up, why is it also a problem?

    Recall what section 2.1.4 said congestion control is for.

What to remember

  • A web page is made of objects, each addressed by a URL of two parts: hostname and path name. The base HTML file is an object too — count it.
  • HTTP is stateless: the server keeps no information about clients. That is what lets one server hold thousands of connections.
  • Non-persistent HTTP costs 2 RTT per object. Persistent with pipelining costs 3 RTT for the whole page, whatever the object count. For a page over a long path, almost all the time is round trips, not bytes.