Javascript HTML5 websockets:最大打开连接数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12475462/
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-23 08:03:03  来源:igfitidea点击:

HTML5 websockets: max number of open connections?

javascripthtmlweb-applicationswebsocket

提问by Joseph Victor Zammit

HTML5 websockets are (and have been for some time) a hot topic as they elegantly enable real-timeserver-side push.

HTML5 websockets 是(并且已经有一段时间)一个热门话题,因为它们优雅地启用实时服务器端推送

I currently have a working application with websockets powered by Tomcat 7.0.30 which includes websocket support. But moving this to a production environment raises questions.

我目前有一个由 Tomcat 7.0.30提供支持的websockets 工作应用程序,其中包括websocket 支持。但是将其迁移到生产环境会引发问题。

Mainly I would like to know the possible maximum number of connections that can operate (be open) concurrently per browsing session; a browsing sessionimplies a single browser tab or window.

主要是我想知道每个浏览会话可以同时操作(打开)的最大连接数;一个浏览会话意味着单个浏览器标签或窗口。

Do open websocket connections add up to the maximum number of connections that can be processed simultaneously by the Web server? E.g. MaxClientsin Apache.

打开的 websocket 连接加起来是否达到了 Web 服务器可以同时处理的最大连接数?例如MaxClients在阿帕奇。

Conversely, is the maximum number of websockets for a single browsing sessionlimited by the browser itself? As this blog postshows, up to April 2012, different browsers support varying amounts of openwebsocket connections. (I personally would aim for 1 open websocket per browsing session; but this info would still be good to know).

相反,单个浏览会话的最大 websocket数量是否受浏览器本身的限制?正如这篇博文所示,截至 2012 年 4 月,不同的浏览器支持不同数量的开放websocket 连接。(我个人的目标是每个浏览会话1 个打开的 websocket ;但是这个信息还是很高兴知道的)。

TL/DR:

TL/DR:

  1. What limits the amount of possible websockets per browsing session? Is it the client? The server? Or a combination of both?
  2. Does the same limitation(s) apply to both ws:and wss:connections?
  1. 什么限制了每个浏览会话可能的 websockets 数量?是客户吗?服务器?还是两者的结合?
  2. 相同的限制是否适用于ws:wss:连接?

回答by Mardie

There isn't a standard specification of max-connectionsdefault value for browsers.It depends on implementation [0]. Furthermore using more than a web-socket per browsing sessionfor the same application seems overkill since you can use pub/sub channels.

浏览器的最大连接数默认值没有标准规范。这取决于实现 [0]。此外,对于同一应用程序,每个浏览会话使用多个 web 套接字似乎有点过分,因为您可以使用发布/订阅渠道。

Bottleneck for connections usually is at server side. Web-socket is a upgrade to HTTP so connections are "just" upgraded HTTP(TCP) connections [1].HTTPS and WSS add just a security layer to the normal connection.They are not a different connection [2]. In your case check maxConnections(and maxThreads) [3] and your Operating System maximums [4][5]. If your concurrent connections reach tens of thousands maybe you should start thinking on load balancing or clustering [6].

连接的瓶颈通常在服务器端。Web-socket 是对 HTTP 的升级,因此连接是“只是”升级的 HTTP(TCP) 连接 [1]。HTTPS 和 WSS 只是为普通连接添加了一个安全层。它们不是不同的连接 [2]。在您的情况下,请检查maxConnections(和maxThreads)[3] 和您的操作系统最大值 [4][5]。如果您的并发连接数达到数万,也许您应该开始考虑负载平衡或集群 [6]。

[0]https://code.google.com/p/chromium/issues/detail?id=85323

[0] https://code.google.com/p/chromium/issues/detail?id=85323

[1]http://en.wikipedia.org/wiki/WebSocket

[1] http://en.wikipedia.org/wiki/WebSocket

[2]http://en.wikipedia.org/wiki/HTTP_Secure

[2] http://en.wikipedia.org/wiki/HTTP_Secure

[3]http://tomcat.apache.org/tomcat-7.0-doc/config/http.html

[3] http://tomcat.apache.org/tomcat-7.0-doc/config/http.html

[4]https://serverfault.com/questions/10852/what-limits-the-maximum-number-of-connections-on-a-linux-server

[4] https://serverfault.com/questions/10852/what-limits-the-maximum-number-of-connections-on-a-linux-server

[5]https://superuser.com/questions/251596/is-there-a-hard-limit-of-65536-open-tcp-connections-per-ip-address-on-linux

[5] https://superuser.com/questions/251596/is-there-a-hard-limit-of-65536-open-tcp-connections-per-ip-address-on-linux

[6]http://tomcat.apache.org/tomcat-7.0-doc/config/cluster.html

[6] http://tomcat.apache.org/tomcat-7.0-doc/config/cluster.html

More about high concurrency: http://www.kegel.com/c10k.html

更多关于高并发:http: //www.kegel.com/c10k.html

回答by Mat

In Gecko 7 they introduced the aprameter network.websocket.max-connectionsyou can set it in about:config. It's setting the maximum websocket connections "at a time" according to this: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API

在 Gecko 7 中,他们引入了network.websocket.max-connections可以在about:config. 它根据以下内容“一次”设置最大 websocket 连接数:https: //developer.mozilla.org/en-US/docs/Web/API/WebSockets_API

I don't know if you can determine this number from the code and if there is any way to determin how many is open in other sessions (so how many you have left).

我不知道你是否可以从代码中确定这个数字,以及是否有任何方法可以确定在其他会话中打开了多少(所以你还剩下多少)。