-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster-dcit.js
36 lines (27 loc) · 994 Bytes
/
cluster-dcit.js
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
34
35
36
var cluster = require('cluster'),
logger = require('./lib/logger.js');
function startWorker() {
var worker = cluster.fork();
logger.info('CLUSTER: Worker %d started', worker.id);
}
if(cluster.isMaster){
require('os').cpus().forEach(function(){
startWorker();
});
// log any workers that disconnect; if a worker disconnects, it
// should then exit, so we'll wait for the exit event to spawn
// a new worker to replace it
cluster.on('disconnect', function(worker){
logger.info('CLUSTER: Worker %d disconnected from the cluster.',
worker.id);
});
// when a worker dies (exits), create a worker to replace it
cluster.on('exit', function(worker, code, signal){
logger.info('CLUSTER: Worker %d died with exit code %d (%s)',
worker.id, code, signal);
startWorker();
});
} else {
// start our app on worker; see dcit.js
require('./dcit.js')();
}