Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 websockets: max number of open connections?

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?
like image 492
Joseph Victor Zammit Avatar asked Sep 18 '12 10:09

Joseph Victor Zammit


People also ask

Is there a limit on number of WebSocket connections?

The theoretical limit is 65k connections per IP address but the actual limit is often more like 20k, so we use multiple addresses to connect 20k to each (50 * 20k = 1 mil).

Would WebSockets be able to handle 1000000 concurrent connections?

With at least 30 GiB RAM you can handle 1 million concurrent sockets.

How many WebSockets can a browser open?

According to Microsoft's official documentation about Internet Explorer 10 and 11, these versions of the Windows default browser support by default WebSocket objects. However the maximum number of concurrent WebSocket connections is limited to 6 per default.

Can a WebSocket have multiple connections?

A server can open WebSocket connections with multiple clients—even multiple connections with the same client. It can then message one, some, or all of these clients. Practically, this means multiple people can connect to our chat app, and we can message some of them at a time.


2 Answers

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

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

[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

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

like image 93
Mardie Avatar answered Oct 10 '22 01:10

Mardie


In Gecko 7 they introduced the aprameter network.websocket.max-connections you 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

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

like image 7
Mat Avatar answered Oct 10 '22 02:10

Mat