Is there a limit (practical or otherwise) to the number of web sockets that the page opens?

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

Are there any recommendations, practical restrictions, or strict limits on the number of web sockets a page can open?

+5
source share
1 answer

It depends on the browser.

Cm:

It seems that the maximum number of possible open web sockets is determined by the browser implementation, and it is difficult to find the numbers.

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

// 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 }; 

In the Firefox configuration (go to about:config and search network.websocket ), I see a maximum of 6 permanent connections to the host and 200 in general, but apparently the constant connection limit does not affect WebSocket connections , so only the 200 limit applies .

About the approach ...

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

Too many connections are a waste of resources both in the browser and on the server.

+8
source

Source: https://habr.com/ru/post/1203253/


All Articles