53

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

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.

Mainly I would like to know the possible maximum number of connections that can operate (be open) concurrently per browsing session; a browsing session implies 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. MaxClients in Apache.

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

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?
4

2 回答 2

36

浏览器的最大连接默认值没有标准规范。它取决于实现 [0]。此外,对于同一个应用程序,每个浏览会话使用多个 web-socket似乎有点过头了,因为您可以使用 pub/sub 通道。

连接的瓶颈通常在服务器端。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

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

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

[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

[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

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

于 2014-02-10T03:34:31.890 回答
7

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

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

于 2012-09-18T11:02:00.703 回答