ArticleslgStudy

science

HTTP persistent connection

HTTP persistent connection is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand HTTP persistent connection rather than just read about it. In short: HTTP persistent connection, also called HTTP keep-alive, or HTTP connection reuse, is the idea of using a single TCP connection to send and receive multiple HTTP requests/responses, as opposed to opening a new connection for every single request/response pair. The newer HTTP/2 protocol uses the same idea and takes it further to allow multiple concurrent requests/responses to be multiplexed over a single connection.

HTTP persistent connection — main illustration
HTTP persistent connection — illustration

Key takeaways

  • HTTP persistent connection belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect HTTP persistent connection to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of HTTP persistent connection from memory before moving on to harder problems.

Reference excerpt

HTTP persistent connection, also called HTTP keep-alive, or HTTP connection reuse, is the idea of using a single TCP connection to send and receive multiple HTTP requests/responses, as opposed to opening a new connection for every single request/response pair. The newer HTTP/2 protocol uses the same idea and takes it further to allow multiple concurrent requests/responses to be multiplexed over a single connection.

Operation

HTTP 1.0 Under HTTP 1.0, connections should always be closed by the server after sending the response. Since at least late 1995, developers of popular products (browsers, web servers, etc.) using HTTP/1.0, started to add an unofficial extension (to the protocol) named "keep-alive" in order to allow the reuse of a connection for multiple requests/responses. If the client supports keep-alive, it adds an additional header to the request:

Connection: keep-alive

When the server receives this request and generates a response, if it supports keep-alive then it also adds the same above header to the response. Following this, the connection is not dropped, but is instead kept open. When the client sends another request, it uses the same connection. This will continue until either the client or the server decides that the conversation is over and in this case they omit the "Connection:" header from the last message sent or, better, they add the keyword "close" to it:

Connection: close

After that the connection is closed following specified rules. Since 1997, the various versions of HTTP/1.1 specifications acknowledged the usage of this unofficial extension and included a few caveats regarding the interoperability between HTTP/1.0 (keep-alive) and HTTP/1.1 clients / servers.

HTTP 1.1 In HTTP 1.1, all connections are considered persistent unless declared otherwise. The HTTP persistent connections do not use separate keepalive messages, they just allow multiple requests to use a single connection. However, the default connection timeout of Apache httpd 1.3 and 2.0 is as little as 15 seconds and just 5 seconds for Apache httpd 2.2 and above. The advantage of a short timeout is the ability to deliver multiple components of a web page quickly while not consuming resources to run multiple server processes or threads for too long.

Keepalive with chunked transfer encoding Keepalive makes it difficult for the client to determine where one response ends and the next response begins, particularly during pipelined HTTP operation. This is a serious problem when Content-Length cannot be used due to streaming. To solve this problem, HTTP 1.1 introduced a chunked transfer coding that defines a last-chunk bit. The last-chunk bit is set at the end of each response so that the client knows where the next response begins.

Advantages Reduced latency in subsequent requests (no handshaking and no slow start). Reduced CPU usage and round-trips because of fewer new connections and TLS handshakes. Enables HTTP pipelining of requests and responses. Reduced network congestion (fewer TCP connections). Errors can be reported without the penalty of closing the TCP connection. According to RFC 7230, section 6.4, "a client ought to limit the number of simultaneous open connections that it maintains to a given server". The previous version of the HTTP/1.1 specification stated specific maximum values but in the words of RFC 7230 "this was found to be impractical for many applications... instead... be conservative when opening multiple connections". These guidelines are intended to improve HTTP response times and avoid congestion. If HTTP pipelining is correctly implemented, there is no performance benefit to be gained from additional connections, while additional connections may cause issues with congestion.

Disadvantages If the client does not close the connection when all of the data it needs has been received, the resources needed to keep the connection open on the server will be unavailable for other clients. This affects both server's availability and the availability of resources on the server, with the degree of impact depending on the server's architecture and configuration. Also a race condition can occur where the client sends a request to the server at the same time that the server closes the TCP connection. A server should send a 408 Request Timeout status code to the client immediately before closing the connection. When a client receives the 408 status code, after having sent the request, it may open a new connection to the server and re-send the request. Not all clients will re-send the request, and many that do will only do so if the request has an idempotent HTTP method.

Use in web browsers

All modern web browsers including Chrome, Edge, Firefox, Opera (since 4.0), and Safari use persistent connections. In Firefox, the number of simultaneous connections can be customized (per-server, per-proxy, total). Persistent connections time out after 115 seconds (1.92 minutes) of inactivity which is changeable via the configuration.

Implementation Python's requests library contains requests.Session(), which establishes a persistent HTTP connection, thereby allowing the underlying TCP connection to be reused, which can result in a significant performance increase.

See also HTTP pipelining, whereby multiple requests can be sent without waiting for a response HTTP/2, which allows out-of-order pipelining of requests and responses, and also predictive pushing of content before it has been requested

References

External links Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing, Connection Management, Persistence Persistent Connection Behavior of Popular Browsers (dated) Apache HTTPD Keep-Alive Support Network Performance Effects of HTTP/1.1, CSS1, and PNG

Illustrations

HTTP persistent connection illustration
HTTP persistent connection: Schema of multiple vs. persistent connection.
Schema of multiple vs. persistent connection.

Worked examples

Example 1 — a first encounter with HTTP persistent connection

Start with the simplest possible case. Write down what HTTP persistent connection claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to HTTP persistent connection before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about HTTP persistent connection ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of HTTP persistent connection

In research
HTTP persistent connection appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses HTTP persistent connection in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
HTTP persistent connection is common in secondary-school and first-year university syllabi. It links to neighbouring topics Hypertext Transfer Protocol, so understanding it makes those chapters shorter.
In everyday life
Look for HTTP persistent connection outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “HTTP persistent connection” →

How to study HTTP persistent connection in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what HTTP persistent connection means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain HTTP persistent connection out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is HTTP persistent connection in simple terms?

HTTP persistent connection, also called HTTP keep-alive, or HTTP connection reuse, is the idea of using a single TCP connection to send and receive multiple HTTP requests/responses, as opposed to opening a new connection for every single request/response pair. The newer HTTP/2 protocol uses the sam…

Why does HTTP persistent connection matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study HTTP persistent connection?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on HTTP persistent connection.

Tags

  • Hypertext Transfer Protocol

Keep exploring