title: Node.js + socket.io determine maximum amount of clients per instance
body: <p>I am asked to perform rough calculation of how many connections can single socket.io instance handle on a large EC2 instance (16Gb Ram, 4 Core Xeon).</p>
  
  <p>I updated sample of simple socket.io benchmark. </p>
  
  <p>Serever:</p>
  
  <pre><code>var io = require('socket.io').listen(80);
  var exec = require('child_process').exec; 
  
  io.configure(function() {
    io.set('log level', 1);
  
    var transport = process.argv.length &gt;= 2 ? process.argv[2] : null;
    if (transport) {
      io.set('transports', [transport]);
    }
  });
  
  var payload = "Payload: Payload line item " +
  "Payload: Payload line item " +
  "Payload: Payload line item " +
  "Payload: Payload line item " +
  "Payload: Payload line item " +
  "Payload: Payload line item " +
  "Payload: Payload line item " +
  "Payload: Payload line item " +
  "Payload: Payload line item " +
  "Payload: Payload line item " +
  "Payload: Payload line item " +
  "Payload: Payload line item " +
  "Payload: Payload line item " +
  "Payload: Payload line item " +
  "Payload: Payload line item " +
  "Payload: Payload line item " +
  "Payload: Payload line item " +
  "Payload: Payload line item " +
  "Payload: Payload line item ";
  
  var users = 0;
  
  function roundNumber(num, precision) {
    return parseFloat(Math.round(num * Math.pow(10, precision)) / Math.pow(10, precision));
  }
  
  setInterval(function() { 
    io.sockets.emit("message", payload);
    console.log("Users: " + users);
  }, 3000);
  
  io.sockets.on('connection', function(socket) {
  
    users++;  
  
    socket.on('disconnect', function() {
      users--;
    })
  });
  </code></pre>
  
  <p>Client</p>
  
  <pre><code>var io = require('socket.io-client');
  
  var message = "o bispo de constantinopla nao quer se desconstantinopolizar";
  
  var receivedMessages = 0;
  
  function user(shouldBroadcast, host, port) {
    var socket = io.connect('http://' + host + ':' + port, {
      'force new connection': true
    });  
  
    socket.on("message", function(){    
      receivedMessages += 1;
    })
  };
  
  var argvIndex = 2;
  
  var users = parseInt(process.argv[argvIndex++]);
  var rampUpTime = parseInt(process.argv[argvIndex++]) * 1000; // in seconds
  var newUserTimeout = rampUpTime / users;
  var shouldBroadcast = process.argv[argvIndex++] === 'broadcast' ? true : false;
  var host = process.argv[argvIndex++] ? process.argv[argvIndex - 1]  : 'localhost';
  var port = process.argv[argvIndex++] ? process.argv[argvIndex - 1]  : '3000';
  
  for(var i=0; i&lt;users; i++) {
    setTimeout(function() { user(shouldBroadcast, host, port); }, i * newUserTimeout);
  };
  
  setInterval(function() {
  
   console.log("Messages received: " + receivedMessages);
   receivedMessages = 0;
  
  }, 3000);
  </code></pre>
  
  <p>I ran this sample, client was started on medium instance, server on large. And I got result amount of received messages around 4500 per 3 seconds.</p>
  
  <p>But the network, cpu and ram usage was in range of 2-10%.</p>
  
  <p>Is it possible to increase the number of served connections?</p>
  
  <p>Server OS is Windows Server 2008 R2.</p>