Created
June 17, 2014 22:23
-
-
Save ivanoats/91244c1966d4b92580a4 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; | |
if (cluster.isMaster) { | |
console.log('I am the master!'); | |
console.log(process.pid); | |
var numToSpin = process.env.WORKERS || os.cpus().length; | |
for(i=0; i < numToSpin; i++) { | |
cluster.fork(); | |
} | |
cluster.on('exit', function(worker){ | |
cluster.fork(); | |
}); | |
} else { | |
console.log('I am a server worker, pid:'+ process.pid); | |
require('./server'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment