使用xhr polling时如何解决Chrome的6个连接限制 [英] How to solve Chrome's 6 connection limit when using xhr polling

查看:24
本文介绍了使用xhr polling时如何解决Chrome的6个连接限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现 Chrome 似乎有 6 个连接限制(Chrome 在传输一定数量的数据后挂起 - 等待可用套接字) 不幸的是,我在加载后也收到等待可用套接字"消息,发现这一点很困难许多标签 (7).

I recently found out that Chrome seems to have a connection limit of 6 ( Chrome hangs after certain amount of data transfered - waiting for available socket ) unfortunately I found this out the hard way by getting a "waiting for available sockets" message after loading up too many tabs (7).

我知道它是 Chrome,因为另一个 Chrome 用户(也就是另一个浏览器会话)可以同时在同一台计算机上完美加载网页(我的计算机上打开了多个 Chrome 用户).所以无论如何它都不是服务器.

I know it is Chrome since another Chrome user (a.k.a another browser session) loads the web page perfectly fine on the same computer at the same time (I have multiple Chrome users open on my computer). So it is not the server in any way.

我相信这是因为,在 socket.io(我用于通知)中,我是 xhr-polling,这导致 Chrome 必须等到它可以从其中一个连接中获取套接字才能处理页面.

I believe this is because, in socket.io (which I am using for notifications), I am xhr-polling which is causing Chrome to have to wait until it can grab a socket from one of those connections before it can process the page.

解决办法是什么?

我想到了几个解决方案:

I have thought of a couple of solutions:

  • 缩小 xhr-polling 窗口,这会增加浏览器和 node.js 中的连接,但意味着页面不会停止.
  • 使用网络套接字.我不确定 websockets 是否也不受这个问题的影响.
  • 在未聚焦的选项卡上使连接处于非活动状态.虽然其他网站似乎不必这样做......
  • 使用某种连接共享.考虑到 Chrome 将 websocket 和 xhr 请求隔离到标签页,我确实很难理解它是如何工作的.

补充一点:我从一开始就没有使用 websockets 的原因是因为我使用了 cloudflare.但如果这是解决问题的方法,那么:就这样吧.

As an added point: the reason I have not gone with websockets from the start is because I use cloudflare. But if this is the way to solve it then: so be it.

推荐答案

使用真正的 webSocket,而不是 XHR 轮询.webSocket 连接不计入到同一来源的 http 连接限制.

Use a real webSocket, rather than XHR Polling. webSocket connections do not count toward the http connection limit to the same origin.

对于可以创建多少个 webSocket 连接有一个单独的全局限制,但这个数字很高(Firefox 中为 200 - 不确定 Chrome 中究竟是什么).

There is a separate global limit to how many webSocket connections can be created, but it is a high number (200 in Firefox - not sure what it is exactly in Chrome).

以下是有关此主题的一些参考资料:

Here are some references on this topic:

最大并发连接数浏览器的相同域

HTTP 同时每个主机的连接数限制……是每个选项卡、浏览器实例还是全局?.

这篇关于使用xhr polling时如何解决Chrome的6个连接限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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