TCP Connection Pooling – What is Meant by TCP Connection Pooling?

connectionlinuxnetworkingpoolwindows

Why is creating a new TCP connection regarded as expensive? was the question I had in mind when another one came to my mind.

What exactly is meant by keeping a TCP connection alive and what is meant by caching a connection through connection pools?
(I do understand thread pools concept but confused with "connection" part of connection pools).

Isn't the TCP traffic supposed to flow through a number of Internet-based IPs (computers and routers etc) before it reaches the destination?
If that is so, then what does a connection even mean? Does it refer to the path established once for TCP traffic and re-using the connection means that the same path is used again and again until some IPs in that path are not available anymore?

Best Answer

TCP connection is initialised by a three-way handshake, where both ends of the connection agree on sequence numbers they are using for packets they send.

When three-way handshake is finished, the connection is in ESTABLISHED state, which means that data can flow bi-directionally.

The individual TCP segments in the connection can take different paths between the sender and receiver. All TCP cares about is that both ends have the same idea about connection state.

Keepling TCP connection alive means that the connection is kept in ESTABLISHED state, even though there is no immediate need to transmit any data via the connection. Web servers use connection pools to manage these open connections to clients.

A practical example of keeping TCP connection open. A website visitor loads https://www.example.com.

  1. The browser opens a TCP connection to https://www.example.com port 443.
  2. The browser does TLS handshake with the web server.
  3. The browser sends GET / request to the web server and server sends response page back.
  4. The browser leaves TCP connection open with the web server.

Visitor then browses through the page and clicks on https://www.example.com/example link.

  1. Now browser can send GET /example request directly to the web server, re-using the existing TCP connection and TLS transport.

If the web server / client did not keep TCP connection open, browser would have to repeat steps 1 and 2 for the second HTTPS request.