I have a simple node js web socket server as follows:
var ws = require("nodejs-websocket")
var connectionCount = 0;
console.info("Node websocket started @ 8001");
var server = ws.createServer(function (conn) {;
console.log("New connection", ++connectionCount);
conn.on("close", function (code, reason) {
console.log("Connection closed")
});
}).listen(8001)
This server takes 65k connections (as one port takes at the max 65k connections). How can I scale the server so that it can take more than 100k connections?
I recently opened three such servers with different ports and tried to do load balancing using nginx but to no avail, as the nginx server also could take 65k connections only. The nginx config is here
upstream localhost {
server localhost:8001;
server localhost:8002;
server localhost:8003;
}
server {
proxy_read_timeout 3600s;
listen 8000;
location / {
proxy_pass http://localhost;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
The port 8000 could take only 65k connections.
How are these kind of situations handled in the real time. I am an amateur here and need some good pointer to scale the server. The solution need not have to be using nginx. It can be anything. I just want to know, how to handle these kind of problems. Detail answers are appreciated. Thanks.