forked from pelias/api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (25 loc) · 695 Bytes
/
index.js
File metadata and controls
32 lines (25 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 );
}