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