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

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

问题描述

我最近发现,Chrome浏览器似乎有6个连接限制( Chrome在一定数量的数据传输后挂起 - 等待可用的套接字)不幸的是,我也发现在加载之后得到一个等待可用套接字消息的困难方式很多标签(7)。

我知道这是Chrome,因为另一个Chrome用户(又名另一个浏览器会话)同时在同一台计算机上完美地加载网页(我的电脑上有多个Chrome用户打开)。所以它不是服务器。



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



这是什么解决方案?

>

我想到了一些解决方案:


  • 使xhr-polling窗口更小,这会增加浏览器和node.js中的连接,但意味着该页面不会停顿。使用websockets。我不确定websockets是否也能解决这个问题。

  • 在不重点关注的选项卡上使连接处于非活动状态。尽管看起来其他网站不必这样做......

  • 使用某种连接共享。考虑到Chrome将websockets和xhr请求隔离到标签中,我发现很难理解它是如何工作的。



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

使用真正的webSocket而不是XHR轮询。 webSocket连接不计入http连接限制为同一个来源。

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



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


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).

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.

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.

What is the solution to this?

I have thought of a couple of solutions:

  • make the xhr-polling window smaller, this increases connections in the browser and node.js but will mean the page won't stall.
  • Use websockets. I am unsure if websockets are immune to this problem either.
  • Make connections inactive on tabs not focused. Though it seems other sites don't have to do that...
  • Use some kind of connection sharing. Considering that Chrome isolates websockets and xhr requests to the tab I do find it difficult to understand how that works.

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.

解决方案

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

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:

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

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