-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcluster.js
More file actions
34 lines (29 loc) · 734 Bytes
/
Copy pathcluster.js
File metadata and controls
34 lines (29 loc) · 734 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
33
'use strict';
/**
* Start in cluster mode.
* Adapted from http://www.godtic.com/blog/2013/07/27/modo-cluster-para-node-js/
* (C) 2013 TuiInnovation.
*/
// requires
var cluster = require('cluster');
var app = require('./lib/app.js');
var log = require('./lib/util/log.js');
// globals
var numCPUs = require('os').cpus().length;
// init
if (cluster.isMaster) {
// create one worker per CPU
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker/*, code, signal*/) {
log.debug('worker ' + worker.process.pid + ' died');
cluster.fork();
});
}
else {
// start the server
app.startServer(function() {
log.info('Worker ' + cluster.worker.id + ' / ' + numCPUs + ' listening');
});
}