Reputation: 14526
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.
Upvotes: 191
Views: 185560
Reputation: 12395
I would like to provide yet another answer in 2023.
We only use websocket in socket.io-client. We have done 2 type of performance tests,
my test team uses JMeter to test up to 5000 concurrent connections. Due to the nature of our product, 5000 connections is enough for us, so we didn't go higher.
I use https://a.testable.io/ to do another performance test. The reason I uses testable (this is NOT a sales pitch for them lol) I can choose ws clients from different locations, e.g. I chose 3 different locations from NA and one location from Asia. I believe this would be more closer to real life scenario than I just run a test script from my local machine(which I do have too). Doing this kind of test caused money, to quote from their technical support words after I did my test, "I see you ran a 20,000 user test successfully today too, great! Less than $20 for a test of this size is by far the best pricing out there :)."
BTW, you can also refer to https://ably.com/topic/scaling-socketio, which the latest published article about socket.io performance I can find.
So in summary I would argue that if you only use websocket, 5000 to 10,000 concurrent connection should not be to hard to achieve.
Upvotes: 3
Reputation: 1110
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.
Upvotes: 20
Reputation: 54
After making configurations, you can check by writing this command on terminal
sysctl -a | grep file
Upvotes: 2
Reputation: 461
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'] })
Upvotes: 46
Reputation: 1233
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.
Upvotes: 18
Reputation: 6205
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
Upvotes: 107