forked from deepwn/deepMiner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster.js
29 lines (27 loc) · 1.07 KB
/
cluster.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
/*
Support for multiple processors (best performance)
by vphelipe
*/
var cluster = require('cluster');
var numCPUs = require('os').cpus().length;
var fs = require('fs');
var banner = fs.readFileSync(__dirname + '/banner', 'utf8');
var conf = JSON.parse(fs.readFileSync(__dirname + '/config.json', 'utf8'));
if (cluster.isMaster) {
console.log(banner);
console.log(' Listen on : ' + conf.lhost + ':' + conf.lport + '\n Pool Host : ' + conf.pool + '\n Ur Wallet : ' + conf.addr + '\n');
console.log('----------------------------------------------------------------------------------------\n');
console.log(`[!] Daemon start. PID: ${process.pid}\n`);
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
};
cluster.on('exit', function(deadWorker, code, signal) {
// On exit, restart process.
var worker = cluster.fork();
var newPID = worker.process.pid;
console.log(`[i] Subprocess restart. PID: ${process.pid}\n`);
});
} else {
require('./server.js');
console.log(`[i] Subprocess start. PID: ${process.pid}\n`);
}