页面打开的网络套接字数量是否有限制(实际或其他)? [英] Is there a limit (practical or otherwise) to the number of web sockets a page opens?

查看:41
本文介绍了页面打开的网络套接字数量是否有限制(实际或其他)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们非常喜欢带有 Web 套接字的异步模型.在我们的一些应用程序中,我们在框架中实现小部件(通常一个页面上多达 10 或 20 个小部件).每个小部件打开一个 Web 套接字以接收状态更改的通知.

We really like the async model with web sockets. In some of our applications, we implement widgets in frames (often as many as 10 or 20 widgets on a page). Each widget opens a web socket to receive notifications of state changes.

对于页面可以打开的 Web 套接字数量是否有任何最佳做法、实际限制或硬性限制?

Are there any best practices, practical limits, or hard limits on the number of web sockets a page can open?

推荐答案

这取决于浏览器.

见:

似乎浏览器实现定义了可能打开的 Websocket 的最大数量,并且很难找到数字.

It seems that the maximum number of possible open Websockets is defined by the browser implementation, and it is being difficult to find numbers.

在 Chromium 源代码(Linux 版 Google Chrome)中,我可以看到每个主机最多 30 个,总共 256 个.

In the Chromium source code (Google Chrome for Linux) I can see a max of 30 per host, 256 overall.

// Limit of sockets of each socket pool.
int g_max_sockets_per_pool[] = {
  256,  // NORMAL_SOCKET_POOL
  256   // WEBSOCKET_SOCKET_POOL
};

// Default to allow up to 6 connections per host. Experiment and tuning may
// try other values (greater than 0).  Too large may cause many problems, such
// as home routers blocking the connections!?!?  See http://crbug.com/12066.
//
// WebSocket connections are long-lived, and should be treated differently
// than normal other connections. 6 connections per group sounded too small
// for such use, thus we use a larger limit which was determined somewhat
// arbitrarily.
// TODO(yutak): Look at the usage and determine the right value after
// WebSocket protocol stack starts to work.
int g_max_sockets_per_group[] = {
  6,  // NORMAL_SOCKET_POOL
  30  // WEBSOCKET_SOCKET_POOL
};

在 Firefox 配置中,(转到 about:config 并搜索 network.websocket)我可以看到每个主机最多有 6 个持久连接,总共有 200 个,但显然持久连接限制不影响 WebSocket 连接,所以只有适用 200 个限制.

In the Firefox configuration, (go to about:config and search for network.websocket) I can see a max of 6 persistent connections per host and 200 overall, but apparently the persistent conection limit does not affect WebSocket connections, so only the 200 limit applies.

我的建议是您应该在每个页面/标签上使用一个.如果您将小部件作为框架,请使用 .postMessage( +info ) 在框架和主页面之间进行通信,并让主页面通过单个连接与服务器通信.使用发布者/订阅者模型允许不同的小部件订阅特定事件.

My recommendation is that you should use one per page/tab. If you have widgets as frames, use .postMessage( +info ) to communicate between frames and the main page, and let the main page communicate with the server with a single connection. Use a publisher/subscriber model to allow different widgets subscribe to particular events.

拥有如此多的连接是对浏览器和服务器资源的浪费.

Having so many connections is a waste of resources in both browser and server.

这篇关于页面打开的网络套接字数量是否有限制(实际或其他)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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