This is the 13th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021.

Parallel connections

The previous article introduced connection multiplexing, so even though “connection multiplexing” allows a TCP connection to transmit multiple requests and responses, these requests and responses are serial: request first, response later; A second request and a second response can then be made.

When a large number of resources need to be requested and there are no dependencies between the resources (such as ten CSS files that are not dependent on each other), we prefer to have ten requests in parallel: ten requests are sent simultaneously (or in short order), and ten responses are returned successively. In this way, the download speed is ten times faster than before.

The front-end programmer simply splits a CSS into ten small files, and the browser automatically creates ten TCP connections at once to request those files.

Why not, then, make ten a hundred, a thousand? It can be faster. – The browser is busy. Creating a TCP connection consumes a certain amount of CPU and memory, which are limited.

So browsers have agreed to limit the number of parallel connections per domain name to six. Some browsers set it to 2, 4, 8, 9, 10, 12, and so on. But this is not a problem for us, since each domain has a maximum of 6 connections, so we can not use more domain names to break the limit? Such as:

  1. Css.cdn.com is dedicated to downloading CSS files
  2. Js.cdn.com is dedicated to downloading JS files
  3. Image.cdn.com is dedicated to downloading image files
  4. Juejin. Cn is dedicated to downloading HTML files

As a result, the maximum number of parallel connections can be extended to 24. But to prevent programmers from abusing this feature, browsers add another limitation: the number of concurrent connections throughout the browser is also capped.

Advantages and disadvantages of parallel connections

  • Advantages: Parallel connection Allows multiple HTTP connections to be established at the same time when bandwidth resources are sufficient, which speeds up page loading.
  • Disadvantages: Parallel connections compete for resources when bandwidth resources are insufficient, and the efficiency decreases. Establishing multiple connections at the same time consumes a lot of memory, and the server can handle too many connections from too many users, so the server can usually close the connection overload from a particular client!

One last word

If this article is helpful to you, or inspired, help pay attention to it, your support is the biggest motivation I insist on writing, thank you for your support.