In AWS node socketcluster cannot connect more than 1000 connections

I start a simple socketcluster node.js server and connect 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 an AWS EC2 (c3-large) ubuntu14.04 instance, only less than 1000 connections connect the same code.

The etc / security / limits.conf parameter has been changed and set the limits for "soft nofile" and "hard nofile" to 65535 in the EC2 instance.

The positive Posix limit proposed by Node.js maxing out of 1000 concurrent connections does not help.

Another sysctl parameter is not much different between my local ubuntu instance and EC2.

Delay may not be a problem, since I tried to connect to the server from several client machines, still the number of connections remains <1000.

Is there any AWS environment variable that could affect performance? Can the number of messages from and from EC2 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);
    });
}
+4
source share
1 answer

My bad, there was no problem with the code or with AWS. In my setup, the switch / isp connection that was used to set up AWS could not handle many connections.

+1
source

All Articles