Rootop 服务器运维与web架构

http/1.1和http2中发起的tcp连接数比较

谷歌浏览器对同一个 host(同一个域名,比如www.rootop.org)可以最多建立6个tcp连接。
不同的浏览器限制也不一样。
资料:https://developers.google.com/web/tools/chrome-devtools/network/issues#queued-or-stalled-requestsdevelopers.google.com
中描述了:
Too many requests are being made on a single domain. On HTTP/1.0 or HTTP/1.1 connections, Chrome allows a maximum of six simultaneous TCP connections per host.

在http/1.1版本协议中,请求头中包含 Connection: keep-alive 头信息,则为使用tcp连接复用。
这样页面中引用的js、css、图片等资源文件会在这6个tcp连接中传输(如果选择的连接中要有几十个资源,则串行传输)。
http2则可以并行传输。

# 通过 http 访问一个网站测试。
用wireshark抓包测试后,通过统计源端口号也确认了chrome发起了6个tcp连接。

# 本地发起连接的源端口号
wireshark过滤规则:

ip.dst==47.105.x.x and ip.src==192.168.1.145 and http.host==www.x.cn

统计后:
55660
55661
55662
55663
55664
55665

# nginx中配置https后,配置http2并抓包
wireshark过滤规则:

ip.dst==47.105.x.x and ip.src==192.168.1.145 and http2.headers.authority==www.x.com


发起的tcp连接源端口号只有一个,并且所有资源文件都在这个tcp连接中传输。

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/4820.html

作者:Venus

服务器运维与性能优化

评论已关闭。