浏览器中的最大并行 HTTP 连接数?
我正在创建一些与 HTTP 服务器的挂起连接(comet、反向 AJAX 等)。 它工作正常,但我看到浏览器只允许同时与给定域有两个挂起的连接。 因此,如果用户在浏览器的 Tab1 中查看我的网站,然后又尝试在 Tab2 中加载它,他们就会用完与我的网站的两个允许的连接。
我想我可以做一些通配符域的事情,我让我的HTTP服务器解析我网站的任何地址,例如:
*.example.com/webapp -> 192.0.2.1 (the actual ip of my server)
所以:
a.example.com/webapp
b.example.com/webapp
c.example.com/webapp
所有仍然指向(www.example.com/webapp
),但浏览器认为它们是不同的域,所以我不会遇到 2 个连接的限制。 这是真的?
即使这是真的 - 所有域中每个浏览器的活动连接数是否有限制? 假设我使用上面的方案 - 例如 Firefox 在任何给定时间只允许 24 个并行连接吗? 比如:
1) a.example.com/webapp
2) www.download.example/hugefile.zip
3) b.example.com/webapp
4) c.example.com/webapp
...
24) x.example.com/webapp
25) // Error - all 24 possible connections currently in use!
我刚刚选择了 24 个连接/Firefox 作为示例。
I am creating some suspended connections to an HTTP server (comet, reverse AJAX, etc). It works ok, but I see the browser only allows two suspended connections to a given domain simultaneously. So if a user is looking at my website in Tab1 of their browser, then also tries loading it in Tab2, they've used up the two allowed connections to my site.
I think I can do some wildcard domain thing, where I have my HTTP server resolve any address to my site like:
*.example.com/webapp -> 192.0.2.1 (the actual ip of my server)
so:
a.example.com/webapp
b.example.com/webapp
c.example.com/webapp
all still point to (www.example.com/webapp
) but the browser considers them different domains, so I don't run into the 2 connection limit. Is this true?
Even if that is true - is there any limit to the number of active connections per browser, across all domains? Say I use the scheme above - does Firefox for example only allow 24 parallel connections at any given time? Something like:
1) a.example.com/webapp
2) www.download.example/hugefile.zip
3) b.example.com/webapp
4) c.example.com/webapp
...
24) x.example.com/webapp
25) // Error - all 24 possible connections currently in use!
I just picked 24 connections/Firefox as an example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
每个服务器/代理的默认同时持久连接的最大数量:
限制是每个服务器/代理,因此您的通配符方案将起作用。
仅供参考:这与 HTTP 1.1 特别相关; 其他协议有单独的关注点和限制(即 SPDY、TLS、HTTP 2)。
Max Number of default simultaneous persistent connections per server/proxy:
The limit is per-server/proxy, so your wildcard scheme will work.
FYI: this is specifically related to HTTP 1.1; other protocols have separate concerns and limitations (i.e., SPDY, TLS, HTTP 2).
HTTP/1.1
来源:http:// /p2p.wrox.com/book-professional-website-performance-optimizing-front-end-back-end-705/
HTTP/2(SPDY)
HTTP/1.1
source: http://p2p.wrox.com/book-professional-website-performance-optimizing-front-end-back-end-705/
HTTP/2(SPDY)
2015 年情况
第一个值是 ConnectionsPerHostname,第二个值是 MaxConnections。
来源是现已解散的 Browserscope 项目。 仍然可以通过 Wayback Machine 查看特定页面。
注意:ConnectionsPerHostname 是浏览器向同一域发出的并发 HTTP 请求的最大数量。
为了增加并发连接的数量,可以将资源(例如图像)托管在不同的域中。 但是,您不能超过
MaxConnections,浏览器在所有域中总共打开的最大连接数。
2020 更新
每个浏览器的并行连接数
setTimeout
的回调中,+requestAnimationFrame
,then
...2015 Situation
The first value is ConnectionsPerHostname and the second value is MaxConnections.
The source is the now defunct Browserscope project. The specific page can still be seen via the Wayback Machine.
Note: ConnectionsPerHostname is the maximum number of concurrent HTTP requests that browsers will make to the same domain.
To increase the number of concurrent connections, one can host resources (e.g. images) in different domains. However, you cannot exceed
MaxConnections, the maximum number of connections a browser will open in total - across all domains.
2020 Update
Number of parallel connections per browser
setTimeout
, +requestAnimationFrame
,then
...各种浏览器对每个主机名的最大连接数有不同的限制; 您可以在 http://www.browserscope.org/?category=network
这里有一篇关于网络性能专家 Steve Souders 的关于连接限制的有趣文章 http://www.stevesouders.com/blog/2008/03/20/roundup-on-parallel-connections/
Various browsers have various limits for maximum connections per host name; you can find the exact numbers at http://www.browserscope.org/?category=network
and here is an interesting article about connection limitations from web performance expert Steve Souders http://www.stevesouders.com/blog/2008/03/20/roundup-on-parallel-connections/
Firefox 在此设置中存储该数字(您可以在
about:config
中找到它):network.http.max-connections-per-server
对于最大连接数,Firefox 会存储该数字在此设置中:
network.http.max-connections
Firefox stores that number in this setting (you find it in
about:config
):network.http.max-connections-per-server
For the max connections, Firefox stores that in this setting:
network.http.max-connections
在 GNU/Linux (Ubuntu) 上的 Firefox 33 上查看
about:config
并搜索connections
我发现:这可能会回答以下部分:跨所有域的每个浏览器的活动连接数是否有限制
跳过了两个属性...
(有趣的是,它们似乎不受每个服务器的限制,但默认值低于全局http连接)
Looking at
about:config
on Firefox 33 on GNU/Linux (Ubuntu), and searchingconnections
I found:That is likely to answer the part is there any limit to the number of active connections per browser, across all domain
skipped two properties...
(interesting, seems like they are not limited per server but have a default value lower than global http connections)
2 个并发请求是许多浏览器设计的有意部分。 有一个“好的 http 客户端”有意遵守的标准。 查看此 RFC 了解原因。
The 2 concurrent requests is an intentional part of the design of many browsers. There is a standard out there that "good http clients" adhere to on purpose. Check out this RFC to see why.
请注意,将每台服务器的浏览器最大连接数增加到过多(正如某些站点所建议的那样)可以并且确实会将其他用户锁定在小型站点之外,而这些站点的托管计划会限制服务器上的总并发连接数。
Note that increasing a browser's max connections per server to an excessive number (as some sites suggest) can and does lock other users out of small sites with hosting plans that limit the total simultaneous connections on the server.
对此没有明确的答案,因为每个浏览器都有自己的配置,并且此配置可能会更改。 如果您在互联网上搜索,您可以找到更改此限制的方法(通常它们被标记为“性能增强方法”。)如果您的网站需要,建议您的用户这样做可能是值得的。
There is no definitive answer to this, as each browser has its own configuration for this, and this configuration may be changed. If you search on the internet you can find ways to change this limit (usually they're branded as "performance enhancement methods.") It might be worth advising your users to do so if it is required by your website.
我的理解是连接限制在客户端是不可更改的。 必须在服务器上更改连接限制才能生效。 默认情况下,许多服务器只允许每个唯一客户端有 2 个连接。
客户端不是浏览器,而是发出 TCP/IP 请求的客户端计算机。
要非常清楚地看到效果,请使用 JMeter 之类的工具向您的服务器主机发起一系列 Web 服务调用 - 它将接受前两个调用,并且在两个调用之一完成之前不会接受另一个调用。 令人惊奇的是,对于 SOA 商店来说,这是至关重要的,但几乎没有人真正意识到这一点。
My understanding is that the connection limit is not changeable on the client side. The connection limit must be changed on the server to have any effect. By default, many servers will only allow 2 connections per unique client.
The client is not the browser, it is the client machine issuing the TCP/IP requests.
To see the effect very clearly, use something like JMeter to fire off a bunch of web service calls to your server host - it will accept the first two and will not accept another until one of the two is completed. The amazing thing about this is that for a SOA shop, this is critical, yet hardly anyone is really aware of it.