Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.