-
-
Save pjkelly/4c2289e18e5a1538f9d2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Load environment variables | |
require('dotenv'); | |
// Cluster Initialization | |
var cluster = require('cluster'); | |
// Code to run if we're in the master process | |
if (cluster.isMaster) { | |
// Count the machine's CPUs | |
var cpuCount = require('os').cpus().length; | |
// Create a worker for each CPU | |
for (var i = 0; i < cpuCount; i += 1) { | |
cluster.fork(); | |
} | |
// Listen for dying workers | |
cluster.on('exit', function (worker) { | |
// Replace the dead worker, we're not sentimental | |
console.log('Worker ' + worker.id + ' died :('); | |
cluster.fork(); | |
}); | |
// Code to run if we're in a worker process | |
} else { | |
require('./newrelic'); | |
require('./app'); | |
console.log('Worker ' + cluster.worker.id + ' running!'); | |
} |
This file contains hidden or 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
var DotEnv = require('dotenv-node'); | |
new DotEnv(); | |
var EnvBang = require('envbang-node'); | |
new EnvBang(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment