Skip to content

Instantly share code, notes, and snippets.

@pjkelly
Forked from heymichaelp/gistify140713.js
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjkelly/4c2289e18e5a1538f9d2 to your computer and use it in GitHub Desktop.
Save pjkelly/4c2289e18e5a1538f9d2 to your computer and use it in GitHub Desktop.
// 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!');
}
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