Node.js socket.io server on os x cannot connect more than 120 clients
I am writing a socket.io-client node.js bot application to test the performance of my socket.io based server application which also runs under node.
Usually the server runs ubuntu linux, but I also have the same server application (node.js, nginx, socket.io) installed and configured on my local dev machine.
If I run my bot - "script" and run 200 bots that create separate connections to the server, I have no problem if I do it with the real server (s) - Linux servers.
But if I connect to my local xs xs based server, I cannot get more than ~ 120 connections.
I am getting disconnects, stale sockets, and an infinite disconnect / reconnect loop which will take longer and longer under standard socket.io settings (trying to reconnect).
In this test, my local dev machine is under almost 0% load, so it is not memory or cpu bound.
I tried the same bot-script from a second local machine to ensure that the problem is not with bots running on the same machine as the server. But I have the same problem.
Once I point the bot-script to the real servers, I have no problem.
When I find myself in the range where the problem occurs, i.e. clicking on more than 120 clients, I tried to access my local dev server with a browser (real user script) and update many times. Sometimes I get "internal server 500".
Makes me think that maybe this is not a .io socket related more to nginx? or some other major limitations of sockets on a regular os x machine (not a server)?
source to share
Everything I had done before posting this question ..... and 3 minutes after that I came across the answer:
Writing to the terminal:
sysctl -a | grep somax
I got the answer:
kern.ipc.somaxconn: 128
so the case is pretty closed.
One only entry in the terminal:
sudo sysctl -w kern.ipc.somaxconn=xyz
where xyz is the number of connections to connect.
Found the answer here: http://b.oldhu.com/2012/07/19/increase-tcp-max-connections-on-mac-os-x/
source to share
The somaxconn value of 128 was an acceptable solution. But in my case, changing that value didn't do it.
This post explains the solution. http://docs.basho.com/riak/latest/ops/tuning/open-files-limit/#Mac-OS-X
The problem is the maximum performance limit and the maximum open file limit. one can view these limits by writing ulimit -u (open documents) ulimit -n (max procc)
Changing the runtime didn't work for me, but the link above explains how to continually change these values ββfor a number of popular operating systems.
After making this change, I had no problem exceeding the previous limits, and my kern.ipc.somaxconn: is still 128 ..
source to share