简体   繁体   English

使用带有 HTTP2 的服务器发送事件时,是否还有实际的 6 个连接限制?

[英]Is there still a practical 6 connection limit when using Server Sent Events with HTTP2?

I've been googling around and I cannot seem to find a straight answer to this question, and some people offer contradictory answers.我一直在谷歌搜索,我似乎无法找到这个问题的直接答案,有些人提供了相互矛盾的答案。

Most browsers have a 6 connection limit for each domain.大多数浏览器对每个域有 6 个连接限制。 So for example, if your website is example.com and it initializes a persistent Server Sent Event connection on page load, then the end user can open that tab five more times, but the sixth tab won't load at all, because the 6 persistent TCP connection has been reached for that domain.例如,如果您的网站是 example.com 并且它在页面加载时初始化了一个持久的服务器发送事件连接,那么最终用户可以再打开该选项卡五次,但第六个选项卡根本不会加载,因为 6已达到该域的持久 TCP 连接。

Now, I see some people saying that this is just a perennial problem with SSE, and the only alternative is hacky workarounds involving detecting this connection limit and then either closing the connections in hidden tabs or closing those connections in those tabs and switching to long polling.现在,我看到有些人说这只是 SSE 的一个长期问题,唯一的替代方法是 hacky 解决方法,涉及检测此连接限制,然后关闭隐藏选项卡中的连接或关闭这些选项卡中的连接并切换到长轮询.

However, some people claim that HTTP2 solves this with multiplexing, such that you can have as many open tabs of that website as you'd like, as all the tabs multiplex onto the same TCP connection.但是,有些人声称 HTTP2 通过多路复用解决了这个问题,这样您就可以根据需要打开该网站的任意多个选项卡,因为所有选项卡都多路复用到同一个 TCP 连接上。 I cannot find a primary source for this claim, nor anyone with significant authority making it either.我找不到此声明的主要来源,也找不到任何具有重要权威的人。

So, is it true?那么,这是真的吗? Does HTTP2 multiplexing solve the issue of the common 6 connection limit for website domains? HTTP2 多路复用是否解决了网站域的常见 6 个连接限制问题? Or is one basically required to instead use websockets if they would like to support many open tabs to their site?或者,如果他们想支持许多打开的选项卡到他们的网站,基本上需要使用 websockets 吗?

I have implemented HTTP/2 in Jetty .我已经在Jetty 中实现了 HTTP/2。

As explained in this answer , with HTTP/2 the max number of concurrent requests that a browser can make to the server is largely increased - not infinite but increased from 6-8 to about 100.正如在这个答案中解释的那样,使用 HTTP/2,浏览器可以向服务器发出的最大并发请求数大大增加 - 不是无限的,而是从 6-8 增加到大约 100。

So yes, multiplexing solves this issue in practice (unless you open more than 100 or so tabs).所以是的,多路复用在实践中解决了这个问题(除非你打开超过 100 个左右的标签)。

Note that this value is configured by servers, so it's possible that a server sends to the client a configuration with max number of concurrent requests set to a small number, but in practice servers have settled on a number around 100.请注意,此值是由服务器配置的,因此服务器可能会向客户端发送一个配置,其中最大并发请求数设置为一个较小的数字,但实际上服务器已确定为 100 左右的数字。

Having said that, you want to also read this other answer for a discussion about SSE vs WebSocket.话虽如此,您还想阅读另一个关于 SSE 与 WebSocket 的讨论的答案

The limit is applied in the browser (not server-side), and varies per browser .该限制适用于浏览器(不是服务器端),并且因浏览器

At least it did as of http/1.1.至少它从 http/1.1 开始。 I've been unable to find any configuration specific to http/2, so I think we have to assume the limits are still there.我一直无法找到任何特定于 http/2 的配置,所以我认为我们必须假设限制仍然存在。 I would assume they've been kept to prevent abuse, or accidental DoS attacks.我认为它们已被保留以防止滥用或意外的 DoS 攻击。

https://developer.mozilla.org/en-US/docs/Mozilla/Preferences/Mozilla_networking_preferences https://developer.mozilla.org/en-US/docs/Mozilla/Preferences/Mozilla_networking_preferences

See network.http.max-persistent-connections-per-server .请参阅network.http.max-persistent-connections-per-server (You can also see it in about:config.) (你也可以在 about:config 中看到它。)

Here are all the settings I see (in Firefox) filtering for "connections":以下是我看到(在 Firefox 中)过滤“连接”的所有设置:

在此处输入图片说明

I wonder if SSE is governed by http.max-connections or the websocket.max-connections ?我想知道 SSE 是由http.max-connections还是websocket.max-connections (Ignoring any per-domain limit, for the moment.) (暂时忽略任何每个域的限制。)

You could also just try it, of course (there were example scripts in my above-linked question).当然,您也可以尝试一下(我上面链接的问题中有示例脚本)。 But unless you control the configuration of all clients, you have to assume some people will be running with a limit of 6.但是,除非您控制所有客户端的配置,否则您必须假设某些人的运行限制为 6。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM