mirror of https://github.com/pelias/api.git
Peter Johnson a.k.a. insertcoffee
8 years ago
committed by
GitHub
2 changed files with 18 additions and 7 deletions
@ -1,20 +1,32 @@
|
||||
|
||||
var Cluster = require('cluster2'), |
||||
var cluster = require('cluster'), |
||||
app = require('./app'), |
||||
port = ( process.env.PORT || 3100 ), |
||||
multicore = true; |
||||
|
||||
/** cluster webserver across all cores **/ |
||||
if( multicore ){ |
||||
var c = new Cluster({ port: port }); |
||||
c.listen(function(cb){ |
||||
|
||||
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 ); |
||||
cb(app); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
/** run server on the default setup (single core) **/ |
||||
else { |
||||
console.log( 'listening on ' + port ); |
||||
app.listen( port ); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue