Html 浏览器中的最大并行 http 连接数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/985431/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:53:45  来源:igfitidea点击:

Max parallel http connections in a browser?

htmlhttpweb-applicationspersistent-connectionweb-performance

提问by

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.

我正在创建一些与 HTTP 服务器(彗星、反向 ajax 等)的挂起连接。它工作正常,但我看到浏览器只允许同时挂起两个连接到给定域。因此,如果用户在浏览器的 Tab1 中查看我的网站,然后还尝试在 Tab2 中加载它,他们已经用完了与我网站的两个允许连接。

I think I can do some wildcard domain thing, where I have my http server resolve any address to my site like:

我想我可以做一些通配符域的事情,我让我的 http 服务器解析我网站的任何地址,例如:

*.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?

all 仍然指向 ( www.example.com/webapp) 但浏览器认为它们是不同的域,所以我没有遇到 2 个连接限制。这是真的?

Even if that istrue - 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:

即使这真的 - 对所有域中每个浏览器的活动连接数是否有任何限制?假设我使用上面的方案 - 例如,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!

I just picked 24 connections/Firefox as an example.

我只是以 24 个连接/Firefox 为例。

回答by Alsciende

Max Number of default simultaneous persistent connections per server/proxy:

每个服务器/代理的最大默认同时持久连接数:

Firefox 2:  2
Firefox 3+: 6
Opera 9.26: 4
Opera 12:   6
Safari 3:   4
Safari 5:   6
IE 7:       2
IE 8:       6
IE 10:      8
Chrome:     6

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 相关;其他协议有单独的关注点和限制(即 SPDY、TLS、HTTP 2)。

回答by Fatih Hayrio?lu

HTTP/1.1

HTTP/1.1

IE 6 and 7:      2
IE 8:            6
IE 9:            6
IE 10:           8
IE 11:           8
Firefox 2:       2
Firefox 3:       6
Firefox 4 to 46: 6
Opera 9.63:      4
Opera 10:        8
Opera 11 and 12: 6
Chrome 1 and 2:  6
Chrome 3:        4
Chrome 4 to 23:  6
Safari 3 and 4:  4

source: http://p2p.wrox.com/book-professional-website-performance-optimizing-front-end-back-end-705/

来源:http: //p2p.wrox.com/book-professional-website-performance-optimizing-front-end-back-end-705/

HTTP/2(SPDY)

HTTP/2(SPDY)

Multiplexed support(one single TCP connection for all requests)

回答by Razan Paul

 BrowserVersion | ConnectionsPerHostname | MaxConnections
----------------------------------------------------------
 Chrome34/32    | 6                      | 10
 IE9            | 6                      | 35
 IE10           | 8                      | 17
 IE11           | 13                     | 17
 Firefox27/26   | 6                      | 17
 Safari7.0.1    | 6                      | 17
 Android4       | 6                      | 17
 ChromeMobile18 | 6                      | 16
 IE Mobile9     | 6                      | 60

The first value is ConnectionsPerHostnameand the second value is MaxConnections.

第一个值是ConnectionsPerHostname,第二个值是MaxConnections

Source: http://www.browserscope.org/?category=network&v=top

来源:http: //www.browserscope.org/?category=network& v=top

Note: ConnectionsPerHostnameis 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.

注意:ConnectionsPerHostname是浏览器将向同一域发出的最大并发 http 请求数。为了增加并发连接的数量,可以在不同域中托管资源(例如图像)。但是,您不能超过 MaxConnections,即浏览器将打开的最大连接总数 - 跨所有域。

2020 Update

2020 更新

Number of parallel connections per browser

每个浏览器的并行连接数

| Browser              | Connections per Domain         | Max Connections                |
| -------------------- | ------------------------------ | ------------------------------ |
| Chrome 81            | 6 [^note1]                     | 256[^note2]                    |
| Edge 18              | *same as Internet Explorer 11* | *same as Internet Explorer 11* |
| Firefox 68           | 9 [^note1] or 6 [^note3]       | 1000+[^note2]                  |
| Internet Explorer 11 | 12 [^note4]                    | 1000+[^note2]                  |
| Safari 13            | 6 [^note1]                     | 1000+[^note2]                  |
  • [^note1]: tested with 72 requests , 1 domain(127.0.0.1)
  • [^note2]: tested with 1002 requests, 6 requests per domain * 167 domains (127.0.0.*)
  • [^note3]: when called in async context, e.g. in callback of setTimeout, + requestAnimationFrame, then...
  • [^note4]: of which the last 6 are follow-ups (2,4,6 available at 0.5s,1s,1.5s respectively)
  • [^note1]:测试了 72 个请求,1 个域(127.0.0.1)
  • [^note2]:测试了 1002 个请求,每个域 6 个请求 * 167 个域 (127.0.0.*)
  • [^note3]:在异步上下文中调用时setTimeout,例如在, + requestAnimationFrame, then... 的回调中
  • [^note4]:其中最后6个是后续(2,4,6分别在0.5s,1s,1.5s可用)

回答by Soroush

Various browsers have various limits for maximum connections per host name; you can find the exact numbers at http://www.browserscope.org/?category=networkand 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/

各种浏览器对每个主机名的最大连接数有各种限制;您可以在http://www.browserscope.org/?category=network 上找到确切的数字, 这里有一篇关于网络性能专家 Steve Souders 的关于连接限制的有趣文章http://www.stevesouders.com/blog/2008/ 03/20/综合并行连接/

回答by palswim

Firefox stores that number in this setting (you find it in about:config): network.http.max-connections-per-server

Firefox 将该号码存储在此设置中(您可以在 中找到about:config):network.http.max-connections-per-server

For the max connections, Firefox stores that in this setting: network.http.max-connections

对于最大连接数,Firefox 将其存储在此设置中: network.http.max-connections

回答by Jethro Larson

Doing testing on a page I saw this behavior:

在页面上进行测试时我看到了这种行为:

Safari 4: 6  
Chrome 6: 7  
FF 4: 6

Edit: Seems that firefox 4 should be able to do 15 connections but that's not the behavior I observed.

编辑:似乎 firefox 4 应该能够进行 15 个连接,但这不是我观察到的行为。

回答by Josh

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 RFCto see why.

2 个并发请求是许多浏览器设计的一个有意部分。有一个标准是“好的 http 客户端”故意遵守的。查看此 RFC以了解原因。

回答by orique

Looking at about:configon Firefox 33 on GNU/Linux (Ubuntu), and searching connectionsI found:

看着about:config在GNU / Linux上的Firefox 33(Ubuntu的),和搜索connections,我发现:

network.http.max-connections: 256

network.http.max-connections: 256

That is likely to answer the part is there any limit to the number of active connections per browser, across all domain

这很可能会回答以下问题:跨所有域的每个浏览器的活动连接数是否有任何限制

network.http.max-persistent-connections-per-proxy: 32

network.http.max-persistent-connections-per-server: 6

network.http.max-persistent-connections-per-proxy: 32

network.http.max-persistent-connections-per-server: 6

skipped two properties...

跳过了两个属性...

network.websocket.max-connections: 200

network.websocket.max-connections: 200

(interesting, seems like they are not limited per server but have a default value lower than global http connections)

(有趣,似乎它们不受每个服务器的限制,但默认值低于全局 http 连接)

回答by Rodney P. Barbati

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.

我的理解是客户端的连接限制是不可更改的。必须在服务器上更改连接限制才能生效。默认情况下,许多服务器只允许每个唯一客户端 2 个连接。

The client is not the browser, it is the client machine issuing the TCP/IP requests.

客户端不是浏览器,而是发出 TCP/IP 请求的客户端机器。

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.

要非常清楚地看到效果,请使用 JMeter 之类的东西向您的服务器主机发出一堆 Web 服务调用 - 它会接受前两个,并且在两个中的一个完成之前不会接受另一个。令人惊奇的是,对于 SOA 商店来说,这是至关重要的,但几乎没有人真正意识到这一点。

回答by John A.

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.

请注意,将每个服务器的浏览器最大连接数增加到过多(如某些站点所建议的那样)可以并且确实将其他用户锁定在具有限制服务器上同时连接总数的托管计划的小型站点之外。