当我在 Chrome 中打开一个网站页面时,为什么会有多个 TCP 连接到服务器? [英] Why are there multiple TCP connections to the server when I open one website page in my Chrome?

查看:25
本文介绍了当我在 Chrome 中打开一个网站页面时,为什么会有多个 TCP 连接到服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网站采用SpringBoot开发,部署在Linux服务器上.当我在 Chrome 中打开一个网站页面并打开 TCP Viewer 时,我看到从我的计算机到服务器有多个 TCP 连接.他们使用完全不同的端口.

The website is developed in SpringBoot and deployed in Linux server. When I open one website page in Chrome, and I open TCP Viewer, I see that there are multiple TCP connections from my computer to the server. They are using totally different ports.

我检查了 Chrome DevTool 中的网络选项卡,我看到请求标头中有 Keep-Alive.我猜它正在使用 Http 1.1 和长连接.

And I check the network tab in Chrome DevTool, I see there is Keep-Alive in the requst header. I guess it is using Http 1.1 and long connections.

所以这让我很困惑.既然是长连接,所有的内容都应该通过一个TCP连接,为什么会有这么多TCP连接?

So this confused me. Since it is long connection, all the content should be through one TCP connection, why are there so many TCP connections?

推荐答案

虽然 HTTP/1.0 和 HTTP/1.1 支持在同一个 TCP 连接内处理多个 HTTP 请求的持久连接,但这些请求仍会在内部依次处理相同的连接.如果一个站点需要很多资源,这种使用单个 TCP 连接的顺序加载会太慢.这样就完成了使用多个 TCP 连接的并行加载.由于大多数站点加载了许多资源(主 HTML、各种 CSS、JavaScript、图像、字体...),因此大多数站点都使用了多个 TCP 连接.

While HTTP/1.0 and HTTP/1.1 support persistent connections where multiple HTTP requests are handled within the same TCP connection, these requests are still handled on after each other within the same connection. If many resources are needed from a site this sequential loading using a single TCP connection would be too slow. Thus parallel loading using multiple TCP connection is done. Since most sites load many resources (main HTML, various CSS, JavaScript, images, fonts...) one sees multiple TCP connections used with most sites.

支持单个 TCP 连接内的 HTTP/2 并行加载.在这种情况下,人们通常只会看到一个站点的单个 TCP 连接.当然,如果从多个站点加载资源(即广告、跟踪...),您也会再次看到多个 TCP 连接 - 但如果 HTTP/2 用于特定目的地,则每个目的地只有一个.

With HTTP/2 parallel loading within a single TCP connection is supported. In this case one will usually see only a single TCP connection to a site. Of course, if resources are loaded from multiple sites (i.e. ads, tracking ...) one will also see multiple TCP connections again - but only one per destination if HTTP/2 is used for the specific destination.

这篇关于当我在 Chrome 中打开一个网站页面时,为什么会有多个 TCP 连接到服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆