1
0
Fork 0
forked from svrjs/svrjs

Partially implemented clustering.

This commit is contained in:
Dorian Niemiec 2024-08-25 19:28:20 +02:00
parent 1f5602626a
commit a92616b0a4

View file

@ -97,8 +97,8 @@ try {
} }
// TODO: after implementing clustering in new SVR.JS // TODO: after implementing clustering in new SVR.JS
//process.singleThreaded = false; process.singleThreaded = false;
process.singleThreaded = true; //process.singleThreaded = true;
process.err4xxcounter = 0; process.err4xxcounter = 0;
process.err5xxcounter = 0; process.err5xxcounter = 0;
@ -1505,10 +1505,10 @@ function start(init) {
}; };
*/ */
/*if (init) { if (init) {
var workersToFork = 1; var workersToFork = 1;
function getWorkerCountToFork() { const getWorkerCountToFork = () => {
var workersToFork = os.availableParallelism ? os.availableParallelism() : os.cpus().length; var workersToFork = os.availableParallelism ? os.availableParallelism() : os.cpus().length;
try { try {
var useAvailableCores = Math.round((os.freemem()) / 50000000) - 1; // 1 core deleted for safety... var useAvailableCores = Math.round((os.freemem()) / 50000000) - 1; // 1 core deleted for safety...
@ -1520,7 +1520,7 @@ function start(init) {
return workersToFork; return workersToFork;
} }
function forkWorkers(workersToFork, callback) { const forkWorkers = (workersToFork, callback) => {
for (var i = 0; i < workersToFork; i++) { for (var i = 0; i < workersToFork; i++) {
if (i == 0) { if (i == 0) {
SVRJSFork(); SVRJSFork();
@ -1535,7 +1535,8 @@ function start(init) {
} }
} }
if (cluster.isPrimary === undefined) { // TODO: saveConfig
/*if (cluster.isPrimary === undefined) {
setInterval(function () { setInterval(function () {
try { try {
saveConfig(); saveConfig();
@ -1598,7 +1599,9 @@ function start(init) {
} }
}); });
}, 300000); }, 300000);
} }*/
/*
if (!cluster.isPrimary && cluster.isPrimary !== undefined) { if (!cluster.isPrimary && cluster.isPrimary !== undefined) {
process.on("message", function (line) { process.on("message", function (line) {
try { try {
@ -1729,7 +1732,7 @@ function start(init) {
} }
rla.prompt(); rla.prompt();
}); });
} }*/
if (cluster.isPrimary || cluster.isPrimary === undefined) { if (cluster.isPrimary || cluster.isPrimary === undefined) {
// Cluster forking code // Cluster forking code
@ -1739,7 +1742,7 @@ function start(init) {
SVRJSInitialized = true; SVRJSInitialized = true;
}); });
cluster.workers[Object.keys(cluster.workers)[0]].on("message", function (msg) { /*cluster.workers[Object.keys(cluster.workers)[0]].on("message", function (msg) {
if (msg.length >= 8 && msg.indexOf("\x12ERRLIST") == 0) { if (msg.length >= 8 && msg.indexOf("\x12ERRLIST") == 0) {
var tries = parseInt(msg.substring(8, 9)); var tries = parseInt(msg.substring(8, 9));
var errCode = msg.substring(9); var errCode = msg.substring(9);
@ -1750,8 +1753,9 @@ function start(init) {
var errno = errors[msg.substring(9)]; var errno = errors[msg.substring(9)];
process.exit(errno ? errno : 1); process.exit(errno ? errno : 1);
} }
}); });*/
/*
// Hangup check and restart // Hangup check and restart
setInterval(function () { setInterval(function () {
if (!closedMaster && !exiting) { if (!closedMaster && !exiting) {
@ -1841,8 +1845,9 @@ function start(init) {
}); });
} }
} }
}, 4550); }, 4550);*/
/*
// Termination of unused good workers // Termination of unused good workers
if (!disableUnusedWorkerTermination && cluster.isPrimary !== undefined) { if (!disableUnusedWorkerTermination && cluster.isPrimary !== undefined) {
setTimeout(function () { setTimeout(function () {
@ -1911,11 +1916,11 @@ function start(init) {
} }
}, 300000); }, 300000);
}, 2000); }, 2000);
}
}
}
}*/ }*/
} }
}
}
}
modLoadingErrors.forEach((modLoadingError) => { modLoadingErrors.forEach((modLoadingError) => {
console.log('Error while loading "' + modLoadingError.modName + '" mod:'); console.log('Error while loading "' + modLoadingError.modName + '" mod:');