Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@parsingphase
Created March 12, 2015 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parsingphase/40c81086903df8967808 to your computer and use it in GitHub Desktop.
Save parsingphase/40c81086903df8967808 to your computer and use it in GitHub Desktop.
console.log('Start...');
var cluster = require('cluster');
console.log('required');
var isMaster = cluster.isMaster;
console.log('isMaster? ' + isMaster);
if (isMaster) {
// Listen for dying workers
cluster.on('exit', function (worker) {
// Replace the dead worker,
// we're not sentimental
console.log('Worker ' + worker.id + ' died, replacing');
cluster.fork();
});
console.log('Forking first worker');
cluster.fork(); // if this is all we do, we hang around indefinitely?
} else {
setTimeout(function () {
throw new Error('dead');
}, 3000);
}
console.log('EOF');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment