Skip to content

Commit

Permalink
Merged failattu/master
Browse files Browse the repository at this point in the history
  • Loading branch information
mrako committed Sep 19, 2015
2 parents f69b4cb + b5f1f15 commit 6dfb790
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,28 @@ var morgan = require('morgan');

var server = require('./app');

var cluster = require('cluster');

var port = process.env.PORT || 8080;
var workers = require('os').cpus().length

server.use(morgan('dev', {immediate: true}));

server.listen(port);
// Clustering to utilize all CPU cores
if (cluster.isMaster) {

// Fork workers
for (var i = 0; i < workers; i++) {
cluster.fork();
}

cluster.on('exit', function (worker, code, signal) {
console.log('Worker ' + worker.process.pid + ' died');
console.log('Spawining new worker...');
cluster.fork();
});
}
else {
server.listen(port);
}
console.log("App listening on port " + port);

0 comments on commit 6dfb790

Please sign in to comment.