Skip to content

Instantly share code, notes, and snippets.

@3rd-Eden
Created July 22, 2011 19:21
Show Gist options
  • Select an option

  • Save 3rd-Eden/1100205 to your computer and use it in GitHub Desktop.

Select an option

Save 3rd-Eden/1100205 to your computer and use it in GitHub Desktop.
Handshake benchmark
var io = require('../').listen(8080)
, child = require('child_process');
io.sockets.on('connection', function () {
// nothing to do there as we are testing the handshake clean up.
});
// Check every 1 sec to see howmany ghost handshakes are allocated
var count = 0
, check = setInterval(function () {
count = Object.keys(io.handshaken).length;
console.log('#' + count + ' handshakes allocated');
}, 1000);
console.log('Listening on port 8080');
// Start the apache benchmark test, and -r to ignore the errors
var ab = child.spawn('ab', [
'-n', 2500
, '-c', 10
, '-r'
, 'http://127.0.0.1:8080/socket.io/1/'
]);
ab.stdout.on('data', function (data) {
console.log(data.toString());
});
ab.stderr.on('data', function (err) {
console.error(err.toString());
});
ab.on('exit', function () {
// wait for the one more sweep
setTimeout(function () {
console.log('Test ' + (count === 0 ? 'finished successfully' : 'failed'));
clearInterval(check);
io.server.close();
}, 40000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment