chore(cores): allow cores==0 to not use cluster at all (even w/ single

core). Good for running debugger. If cores==1, it will use cluster to
restart the single node on error
This commit is contained in:
Tyler Renelle
2015-01-08 13:19:11 -07:00
parent 0b28f6df55
commit 6626103d06
+3 -4
View File
@@ -7,12 +7,11 @@ utils.setupConfig();
var logging = require('./logging');
var isProd = nconf.get('NODE_ENV') === 'production';
var isDev = nconf.get('NODE_ENV') === 'development';
var cores = +nconf.get("CORES");
if (cluster.isMaster && (isDev || isProd)) {
if (cores!==0 && cluster.isMaster && (isDev || isProd)) {
// 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);
_.times(cores || require('os').cpus().length-1, cluster.fork);
cluster.on('disconnect', function(worker, code, signal) {
var w = cluster.fork(); // replace the dead worker