-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathapp.js
36 lines (26 loc) · 815 Bytes
/
app.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
/**
* Module dependencies.
*/
var cluster = require('cluster'),
redisClient = require('redis').createClient();
var workersPerCPU = 4;
console.log('Master process starting');
redisClient.set("verify-redis-connectivity - app.js", "seems to be working", function(err, response){
// Count the machine's CPUs
var cpuCount = require('os').cpus().length;
cluster.setupMaster({
exec : 'worker.js'
});
// Create a worker for each CPU
for(var i = 0; i < cpuCount; i += 1){
for(var j = 0; j < workersPerCPU; j += 1){
cluster.fork();
}
}
// Restart dead workers
cluster.on('exit', function (worker) {
console.log('Worker ' + worker.id + ' died :(');
cluster.fork();
});
console.log('Master process started');
});