chore(multi-core): allow "CORES" nconf var, so can just use one core (or

however many) cc @paglias
This commit is contained in:
Tyler Renelle 2014-12-03 19:12:20 -07:00
parent 1a84d01933
commit c14af0e855
2 changed files with 5 additions and 3 deletions

View file

@ -1,6 +1,7 @@
{
"PORT":3000,
"IP":"0.0.0.0",
"CORES":1,
"BASE_URL":"http://localhost",
"FACEBOOK_KEY":"123456789012345",
"FACEBOOK_SECRET":"aaaabbbbccccddddeeeeffff00001111",

View file

@ -9,9 +9,10 @@ var isProd = nconf.get('NODE_ENV') === 'production';
var isDev = nconf.get('NODE_ENV') === 'development';
if (cluster.isMaster && (isDev || isProd)) {
// Fork workers.
var cpus = require('os').cpus();
_.times(nconf.get("HEROKU_PROD") ? (cpus.length-1 || 1) : (_.min([cpus.length,2])), cluster.fork);
// Fork workers. If config.json has CORES=x, use that - otherwise, use all cpus-1 (production)
var cpus = require('os').cpus(),
cores = +nconf.get("CORES");
_.times(cores || cpus.length-1, cluster.fork);
cluster.on('disconnect', function(worker, code, signal) {
var w = cluster.fork(); // replace the dead worker