Created
June 17, 2014 22:01
-
-
Save ivanoats/6f7e5c76bd02ac37d218 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var cluster = require('cluster'); | |
var os = require('os'); | |
var i; | |
// Am I the master of the cluster? | |
// YES - spawn the workers | |
// NO - run the work | |
if (cluster.isMaster) { | |
console.log('I am the master!'); | |
console.log(process.pid); | |
for(i=0; i < os.cpus().length; i++) { | |
cluster.fork(); | |
} | |
cluster.on('exit', function(worker){ | |
cluster.fork(); | |
}); | |
} else { | |
console.log('I am a worker'); | |
console.log(process.pid); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment