Enabled cluster mode

This commit is contained in:
benweet 2014-08-20 00:26:01 +01:00
parent d1b0b86fbe
commit 3e061019ea

View File

@ -1,7 +1,22 @@
var cluster = require('cluster');
var app = require('./app'); var app = require('./app');
// Listen on port 3000 var count = require('os').cpus().length;
var port = process.env.PORT || 3000;
app.listen(port, null, function() { if(!process.env.NO_CLUSTER && cluster.isMaster) {
for(var i = 0; i < count; i++) {
cluster.fork();
}
cluster.on('exit', function(worker) {
console.log('Worker died. Spawning a new process...');
cluster.fork();
});
}
else {
// Listen on port 3000
var port = process.env.PORT || 3000;
app.listen(port, null, function() {
console.log('Server started: http://localhost:' + port); console.log('Server started: http://localhost:' + port);
}); });
}