Skip to content

Instantly share code, notes, and snippets.

@alsotang
Created October 27, 2015 04:07
Show Gist options
  • Select an option

  • Save alsotang/2fe776592014af74ffa2 to your computer and use it in GitHub Desktop.

Select an option

Save alsotang/2fe776592014af74ffa2 to your computer and use it in GitHub Desktop.
var cluster = require('cluster');
if (cluster.isMaster) {
for (var i = 0; i < 4; i++) {
setTimeout(function () {
cluster.fork();
}, i * 2 * 1000)
}
} else {
function work() {
console.log('I am %s', cluster.worker.id);
}
work()
setInterval(work, 8 * 1000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment