Maximum concurrent Socket.IO connections

Websocketsocket.io

Websocket Problem Overview


This question has been asked previously but not recently and not with a clear answer.

Using Socket.io, is there a maximum number of concurrent connections that one can maintain before you need to add another server?

Does anyone know of any active production environments that are using websockets (particularly socket.io) on a massive scale? I'd really like to know what sort of setup is best for maximum connections?

Because Websockets are built on top of TCP, my understanding is that unless ports are shared between connections you are going to be bound by the 64K port limit. But I've also seen reports of 512K connections using Gretty. So I don't know.

Websocket Solutions


Solution 1 - Websocket

This article may help you along the way: http://drewww.github.io/socket.io-benchmarking/

I wondered the same question, so I ended up writing a small test (using XHR-polling) to see when the connections started to fail (or fall behind). I found (in my case) that the sockets started acting up at around 1400-1800 concurrent connections.

This is a short gist I made, similar to the test I used: https://gist.github.com/jmyrland/5535279

Solution 2 - Websocket

I tried to use socket.io on AWS, I can at most keep around 600 connections stable.

And I found out it is because socket.io used long polling first and upgraded to websocket later.

after I set the config to use websocket only, I can keep around 9000 connections.

Set this config at client side:

const socket = require('socket.io-client')
const conn = socket(host, { upgrade: false, transports: ['websocket'] })

Solution 3 - Websocket

This guy appears to have succeeded in having over 1 million concurrent connections on a single Node.js server.

http://blog.caustik.com/2012/08/19/node-js-w1m-concurrent-connections/

It's not clear to me exactly how many ports he was using though.

Solution 4 - Websocket

> GO THROUGH THE COMMENT OF THIS ANSWER BEFORE PROCEEDING FURTHER > > The question ask about socket.io sockets, the answer is for native > sockets. These changes are dangerous as they apply to everything on > the system, not just socket.io sockets. Besides, today networks is > never the bottleneck for socket.io. Do not make these changes to your > system without understanding the implications first.

For +300k concurrent connection:

Set these variables in /etc/sysctl.conf:

fs.file-max = 10000000 
fs.nr_open = 10000000

Also, change these variables in /etc/security/limits.conf:

* soft nofile 10000000
* hard nofile 10000000
root soft nofile 10000000
root hard nofile 10000000

And finally, increase TCP buffers in /etc/sysctl.conf, too:

net.ipv4.tcp_mem = 786432 1697152 1945728
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216

for more information please refer to this.

Solution 5 - Websocket

After making configurations, you can check by writing this command on terminal

sysctl -a | grep file

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndrewView Question on Stackoverflow
Solution 1 - WebsocketJAMView Answer on Stackoverflow
Solution 2 - WebsocketSalem ChenView Answer on Stackoverflow
Solution 3 - WebsocketDaniel NalbachView Answer on Stackoverflow
Solution 4 - WebsocketMajidJafariView Answer on Stackoverflow
Solution 5 - WebsocketSithcoderView Answer on Stackoverflow