Skip to content

Instantly share code, notes, and snippets.

@ivanoats
Created June 17, 2014 22:23
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 ivanoats/91244c1966d4b92580a4 to your computer and use it in GitHub Desktop.
Save ivanoats/91244c1966d4b92580a4 to your computer and use it in GitHub Desktop.
'use strict';
var cluster = require('cluster');
var os = require('os');
var i;
if (cluster.isMaster) {
console.log('I am the master!');
console.log(process.pid);
var numToSpin = process.env.WORKERS || os.cpus().length;
for(i=0; i < numToSpin; i++) {
cluster.fork();
}
cluster.on('exit', function(worker){
cluster.fork();
});
} else {
console.log('I am a server worker, pid:'+ process.pid);
require('./server');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment