forked from svrjs/svrjs
Disabled killing workers, when server is closed.
This commit is contained in:
parent
68a42ccde8
commit
6515a54471
1 changed files with 50 additions and 48 deletions
96
svr.js
96
svr.js
|
@ -5198,61 +5198,63 @@ function start(init) {
|
||||||
if(cluster.isMaster !== undefined) {
|
if(cluster.isMaster !== undefined) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
setInterval(function () {
|
setInterval(function () {
|
||||||
var allClusters = Object.keys(cluster.workers);
|
if (!closedMaster && !exiting) {
|
||||||
var minClusters = Math.ceil(cpus / 2);
|
var allClusters = Object.keys(cluster.workers);
|
||||||
if(minClusters < 2) minClusters = 2;
|
var minClusters = Math.ceil(cpus / 2);
|
||||||
var goodWorkers = [];
|
if(minClusters < 2) minClusters = 2;
|
||||||
function checkWorker(callback, _id) {
|
var goodWorkers = [];
|
||||||
if(typeof _id === "undefined") _id = 0;
|
function checkWorker(callback, _id) {
|
||||||
if(_id >= allClusters.length) {
|
if(typeof _id === "undefined") _id = 0;
|
||||||
callback();
|
if(_id >= allClusters.length) {
|
||||||
return;
|
callback();
|
||||||
}
|
return;
|
||||||
try {
|
|
||||||
if (cluster.workers[allClusters[_id]]) {
|
|
||||||
isWorkerHungUpBuff = true;
|
|
||||||
cluster.workers[allClusters[_id]].on("message", msgListener);
|
|
||||||
cluster.workers[allClusters[_id]].send("\x14KILLPING");
|
|
||||||
setTimeout(function() {
|
|
||||||
if (isWorkerHungUpBuff) {
|
|
||||||
checkWorker(callback, _id+1);
|
|
||||||
} else {
|
|
||||||
goodWorkers.push(allClusters[_id]);
|
|
||||||
checkWorker(callback, _id+1);
|
|
||||||
}
|
|
||||||
}, 250);
|
|
||||||
} else {
|
|
||||||
checkWorker(callback, _id+1);
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
|
||||||
if (cluster.workers[allClusters[_id]]) {
|
|
||||||
cluster.workers[allClusters[_id]].removeAllListeners("message");
|
|
||||||
cluster.workers[allClusters[_id]].on("message", bruteForceListenerWrapper(cluster.workers[allClusters[_id]]));
|
|
||||||
cluster.workers[allClusters[_id]].on("message", listenConnListener);
|
|
||||||
}
|
|
||||||
checkWorker(callback, _id+1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
checkWorker(function() {
|
|
||||||
if (goodWorkers.length > minClusters) {
|
|
||||||
var wN = Math.floor(Math.random() * goodWorkers.length);
|
|
||||||
if (wN == goodWorkers.length) return;
|
|
||||||
try {
|
try {
|
||||||
if (cluster.workers[goodWorkers[wN]]) {
|
if (cluster.workers[allClusters[_id]]) {
|
||||||
isWorkerHungUpBuff = true;
|
isWorkerHungUpBuff = true;
|
||||||
cluster.workers[goodWorkers[wN]].on("message", msgListener);
|
cluster.workers[allClusters[_id]].on("message", msgListener);
|
||||||
cluster.workers[goodWorkers[wN]].send("\x14KILLREQ");
|
cluster.workers[allClusters[_id]].send("\x14KILLPING");
|
||||||
|
setTimeout(function() {
|
||||||
|
if (isWorkerHungUpBuff) {
|
||||||
|
checkWorker(callback, _id+1);
|
||||||
|
} else {
|
||||||
|
goodWorkers.push(allClusters[_id]);
|
||||||
|
checkWorker(callback, _id+1);
|
||||||
|
}
|
||||||
|
}, 250);
|
||||||
|
} else {
|
||||||
|
checkWorker(callback, _id+1);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (cluster.workers[goodWorkers[wN]]) {
|
if (cluster.workers[allClusters[_id]]) {
|
||||||
cluster.workers[goodWorkers[wN]].removeAllListeners("message");
|
cluster.workers[allClusters[_id]].removeAllListeners("message");
|
||||||
cluster.workers[goodWorkers[wN]].on("message", bruteForceListenerWrapper(cluster.workers[goodWorkers[wN]]));
|
cluster.workers[allClusters[_id]].on("message", bruteForceListenerWrapper(cluster.workers[allClusters[_id]]));
|
||||||
cluster.workers[goodWorkers[wN]].on("message", listenConnListener);
|
cluster.workers[allClusters[_id]].on("message", listenConnListener);
|
||||||
}
|
}
|
||||||
serverconsole.locwarnmessage("There was a problem, while terminating unused worker process. Reason: " + err.message);
|
checkWorker(callback, _id+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
checkWorker(function() {
|
||||||
|
if (goodWorkers.length > minClusters) {
|
||||||
|
var wN = Math.floor(Math.random() * goodWorkers.length);
|
||||||
|
if (wN == goodWorkers.length) return;
|
||||||
|
try {
|
||||||
|
if (cluster.workers[goodWorkers[wN]]) {
|
||||||
|
isWorkerHungUpBuff = true;
|
||||||
|
cluster.workers[goodWorkers[wN]].on("message", msgListener);
|
||||||
|
cluster.workers[goodWorkers[wN]].send("\x14KILLREQ");
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (cluster.workers[goodWorkers[wN]]) {
|
||||||
|
cluster.workers[goodWorkers[wN]].removeAllListeners("message");
|
||||||
|
cluster.workers[goodWorkers[wN]].on("message", bruteForceListenerWrapper(cluster.workers[goodWorkers[wN]]));
|
||||||
|
cluster.workers[goodWorkers[wN]].on("message", listenConnListener);
|
||||||
|
}
|
||||||
|
serverconsole.locwarnmessage("There was a problem, while terminating unused worker process. Reason: " + err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}, 120000);
|
}, 120000);
|
||||||
}, 2500);
|
}, 2500);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue