Enabled cluster mode
This commit is contained in:
parent
d1b0b86fbe
commit
3e061019ea
25
server.js
25
server.js
@ -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) {
|
||||||
console.log('Server started: http://localhost:' + port);
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user