Created
May 4, 2016 03:59
-
-
Save blackavec/4ac6fe60b863383779b3a5368e3a5e36 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
require('./bootstrap'); | |
var cluster = require('cluster'); | |
var numCPUs = require('os').cpus().length; | |
if (cluster.isMaster) { | |
for (var i = 0; i < numCPUs; i++) { | |
cluster.fork(); | |
} | |
console.log('[CLUSTER] Worker' + (numCPUs > 1 ? 's': '') + ' count: "' + numCPUs.toString() + '"'); | |
cluster.on('exit', function (worker) { | |
'use strict'; | |
console.log('[RIP] Worker "' + worker.process.pid + '" died.'); | |
cluster.fork(); | |
console.log('[CPR] Worker recovered.'); | |
}); | |
} else { | |
// each worker run this server | |
// you can change this to what ever your app entry file is | |
require('./app.js'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please, what is in ./bootstrap ?
Can i pass to app.js some parameter which tells it forked number / which forked number it is?