Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Websocket (node.js) connection limit, clients are getting disconnected after reaching 400-450 connections

I have a big problem with socket.io connection limit. If the number of connections is more than 400-450 connected clients (by browsers) users are getting disconnected. I increased soft and hard limits for tcp but it didn't help me. The problem is only for browsers. When I tried to connect by socket-io-client module from other node.js server I reached 5000 connected clients. Its very big problem for me and totally blocked me. Please help.

Update

I have tried with standard Websocket library (ws module with node.js) and problem was similar. I can reach only 456 connected clients.

Update 2

I devided connected clients between a few instances of server. Every group of clients were connecting by other port. Unfortunately this change didn't help me. Sum of connected users was the same like before.

Solved (2018)

There were not enough open ports for a Linux user which run the pm2 manager ("pm2" or "pm" username).

like image 808
Piotr Chludziński Avatar asked Oct 26 '15 08:10

Piotr Chludziński


People also ask

How many WebSocket connections can node js handle?

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). I then run the web server as root by typing sudo -i followed by ulimit -n 1024000 and then node examples/WebSocket. js (in the uWebSockets.

Is there a limit on number of WebSocket connections?

Using a WebSocket library of your choice to connect to the server. After the 10th connection no more connections are accepted by the server.

How do you increase the number of WebSocket connections a server can handle?

The server can handle 65,536 sockets per single IP address. So the quantity can be easily extended by adding additional network interfaces to a server.

How many concurrent connections can node js handle?

To address these issues, Node. JS uses a single thread with an event-loop. In this way, Node can handle 1000s of concurrent connections without any of the traditional detriments associated with threads.


1 Answers

You may be hitting a limit in your operating system. There are security limits in the number of concurrent files open, take a look at this thread.

https://github.com/socketio/socket.io/issues/1393

Update: I wanted to expand this answer because I was answering from mobile before. Each new connection that gets established is going to open a new file descriptor under your node process. Of course, each connection is going to use some portion of RAM. You would most likely run into the FD limit first before running out of RAM (but that depends on your server).

Check your FD limits: https://rtcamp.com/tutorials/linux/increase-open-files-limit/

And lastly, I suspect your single client concurrency was not using the correct flags to force new connections. If you want to test concurrent connections from one client, you need to set a flag on the webserver:

var socket = io.connect('http://localhost:3000', {'force new connection': true});

like image 146
Christian Davis Avatar answered Nov 10 '22 16:11

Christian Davis