Skip to content

Instantly share code, notes, and snippets.

@shaunlee
Last active June 10, 2018 12:29
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 shaunlee/40c408eb4aea862beb0c to your computer and use it in GitHub Desktop.
Save shaunlee/40c408eb4aea862beb0c to your computer and use it in GitHub Desktop.
NodeJS Cluster
var cluster = require('cluster'),
numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
while (numCPUs-- > 0) cluster.fork();
cluster.on('exit', function(worker, code, signal) {
console.log('worker ' + worker.process.pid + ' died');
cluster.fork();
});
} else {
var settings = require(__dirname + '/settings.json');
require('./app').listen(settings.port);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment