You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
|
|
var cluster = require('cluster'),
|
|
|
|
app = require('./app'),
|
|
|
|
port = ( process.env.PORT || 3100 ),
|
|
|
|
multicore = true;
|
|
|
|
|
|
|
|
/** cluster webserver across all cores **/
|
|
|
|
if( multicore ){
|
|
|
|
|
|
|
|
var numCPUs = require('os').cpus().length;
|
|
|
|
if( cluster.isMaster ){
|
|
|
|
|
|
|
|
// fork workers
|
|
|
|
for (var i = 0; i < numCPUs; i++) {
|
|
|
|
cluster.fork();
|
|
|
|
}
|
|
|
|
|
|
|
|
cluster.on('exit', function( worker, code, signal ){
|
|
|
|
console.log('worker ' + worker.process.pid + ' died');
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
app.listen( port );
|
|
|
|
console.log( 'worker: listening on ' + port );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** run server on the default setup (single core) **/
|
|
|
|
else {
|
|
|
|
console.log( 'listening on ' + port );
|
|
|
|
app.listen( port );
|
|
|
|
}
|