Skip to content

Instantly share code, notes, and snippets.

@tanner0101
Created June 13, 2016 02:51
Show Gist options
  • Save tanner0101/ca7aa7f639c291f05a10e570a0cc739c to your computer and use it in GitHub Desktop.
Save tanner0101/ca7aa7f639c291f05a10e570a0cc739c to your computer and use it in GitHub Desktop.
Express Benchmark
var cluster = require('cluster');
if(cluster.isMaster) {
var cpuCount = require('os').cpus().length;
for(var i = 0; i < cpuCount; i += 1) {
cluster.fork();
}
cluster.on('exit', function(worker) {
console.log('Worker %d died, replacing', worker.id);
cluster.fork();
});
} else {
var app = require('./app.js');
app.app.listen(app.port, function() {
console.log('Benchmarking worker %d listening on %d', cluster.worker.id, app.port)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment