From c14af0e855865dbc0925309629414bdeaa179267 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Wed, 3 Dec 2014 19:12:20 -0700 Subject: [PATCH] chore(multi-core): allow "CORES" nconf var, so can just use one core (or however many) cc @paglias --- config.json.example | 1 + src/server.js | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/config.json.example b/config.json.example index c60f7c20e9..d8bb67b62e 100644 --- a/config.json.example +++ b/config.json.example @@ -1,6 +1,7 @@ { "PORT":3000, "IP":"0.0.0.0", + "CORES":1, "BASE_URL":"http://localhost", "FACEBOOK_KEY":"123456789012345", "FACEBOOK_SECRET":"aaaabbbbccccddddeeeeffff00001111", diff --git a/src/server.js b/src/server.js index aed0b524b6..8e551f7891 100644 --- a/src/server.js +++ b/src/server.js @@ -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