Skip to content

Instantly share code, notes, and snippets.

@jugglinmike
Created October 27, 2012 18:30
Show Gist options
  • Save jugglinmike/3965600 to your computer and use it in GitHub Desktop.
Save jugglinmike/3965600 to your computer and use it in GitHub Desktop.
Node.js's "cluster" module usage
var cluster = require("cluster");
var os = require("os");
var numCPUs = os.cpus().length;
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
console.log('worker ' + worker.process.pid + ' died');
});
return;
}
// worker logic here...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment