Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On AWS node socketcluster can't connect more than 1000 connections

I am running a simple socketcluster node.js server and connecting to it from node.js websocket client.

By running the server on my local Ubuntu14.04, I could connect more than 10,000 clients to the server. But on AWS EC2 (c3-large) ubuntu14.04 instance the same code connects only less than 1000 connections.

Modified the etc/security/limits.conf and set the limits for "soft nofile" and "hard nofile" to 65535 on the EC2 instance.

Posix soft limit as suggested Node.js maxing out at 1000 concurrent connections is not helping.

Other sysctl parameter doesn't differ much between my local ubuntu and EC2 instance.

Latency might not be an issue, because I tried to connect to server from multiple client machines still number of connection remain < 1000.

Is there any AWS environment variable that could effect the performance? Is number of messages to and from EC2 could be a limitation?

var posix = require('posix');
posix.setrlimit('nofile', {soft:10000});

var SocketCluster = require('socketcluster').SocketCluster;
var numCPUs = require('os').cpus().length;
var numWorkers = numCPUs;

var start = Date.now();
console.log("..... Starting Server....");

process.on('uncaughtException', function (err) {
    console.log("***** SEVERE ERROR OCCURED!!! *****");
    console.log(err);
});

var socketCluster = new SocketCluster({
  balancers: 1,
  workers: numWorkers,
  stores: 1,
  port: 7000,
  appName: 'mysimapp',
  workerController: __dirname + '/sim_server.js',
  addressSocketLimit: 0,
  socketEventLimit: 100,
 rebootWorkerOnCrash: true,
 useSmartBalancing: true
});

--sim_server.js--

module.exports.run = function(worker) {
var posix = require('posix');
posix.setrlimit('nofile', {soft:10000});

var connection_db = {};
var opencount = 0;
var closecount = 0;
var msgcount = 0;

function status()
{
    console.log('open: ' + opencount);
    console.log('close: ' + closecount);
    //console.log('receive: ' + msgcount);
    setTimeout(function(){
      status();
    },10000);
}
status();

websocket_server = worker.getSCServer();

websocket_server.on('connection', function(socket){
    var mac;
    socket.on('mac-id', function(data) {
        opencount++;
        mac = data;
        connection_db[mac] = socket;
    });
    socket.on('message', function(data) {
        msgcount++;
    });
    socket.on('close', function() {
        delete connection_db[mac];
        closecount++;
    });
});

process.once('SIGINT', function() {
    process.exit(0);
    });
}
like image 936
satish Avatar asked Nov 10 '22 17:11

satish


1 Answers

My bad, there wasn't any issue in code or with AWS. In my setup the switch/isp-connection that was used for AWS setup was not able to handle many connections.

like image 152
satish Avatar answered Nov 14 '22 22:11

satish