forked from svrjs/svrjs
Improved minimum thread count calculation algorithm even further. Also disabled x-svr-js-from-main-thread requests from non-localhost clients.
This commit is contained in:
parent
889207e6a2
commit
08cc0ac042
1 changed files with 7 additions and 11 deletions
18
svr.js
18
svr.js
|
@ -2022,7 +2022,7 @@ if (!cluster.isPrimary) {
|
||||||
}
|
}
|
||||||
return ph;
|
return ph;
|
||||||
}
|
}
|
||||||
if (req.headers["x-svr-js-from-main-thread"] == "true") {
|
if (req.headers["x-svr-js-from-main-thread"] == "true" && (!req.socket.remoteAddress || req.socket.remoteAddress == "::1" || req.socket.remoteAddress == "::ffff:127.0.0.1" || req.socket.remoteAddress == "127.0.0.1" || req.socket.remoteAddress == "localhost")) {
|
||||||
var headers = getCustomHeaders();
|
var headers = getCustomHeaders();
|
||||||
res.writeHead(204, "No Content", headers);
|
res.writeHead(204, "No Content", headers);
|
||||||
res.end();
|
res.end();
|
||||||
|
@ -2922,7 +2922,7 @@ if (!cluster.isPrimary) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.headers["x-svr-js-from-main-thread"] == "true") {
|
if (request.headers["x-svr-js-from-main-thread"] == "true" && (!request.socket.remoteAddress || request.socket.remoteAddress == "::1" || request.socket.remoteAddress == "::ffff:127.0.0.1" || request.socket.remoteAddress == "127.0.0.1" || request.socket.remoteAddress == "localhost")) {
|
||||||
var headers = getCustomHeaders();
|
var headers = getCustomHeaders();
|
||||||
response.writeHead(204, "No Content", headers);
|
response.writeHead(204, "No Content", headers);
|
||||||
response.end();
|
response.end();
|
||||||
|
@ -5120,7 +5120,7 @@ function start(init) {
|
||||||
"X-SVR-JS-From-Main-Thread": "true",
|
"X-SVR-JS-From-Main-Thread": "true",
|
||||||
"User-Agent": (exposeServerVersion ? "SVR.JS/" + version + " (" + getOS() + "; " + (process.isBun ? ("Bun/v" + process.versions.bun + "; like Node.JS/" + process.version) : ("Node.JS/" + process.version)) + ")" : "SVR.JS")
|
"User-Agent": (exposeServerVersion ? "SVR.JS/" + version + " (" + getOS() + "; " + (process.isBun ? ("Bun/v" + process.versions.bun + "; like Node.JS/" + process.version) : ("Node.JS/" + process.version)) + ")" : "SVR.JS")
|
||||||
},
|
},
|
||||||
timeout: 1625,
|
timeout: 1620,
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
}, function (res) {
|
}, function (res) {
|
||||||
chksocket.removeAllListeners("timeout");
|
chksocket.removeAllListeners("timeout");
|
||||||
|
@ -5146,7 +5146,7 @@ function start(init) {
|
||||||
else crashed = false;
|
else crashed = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connection.setTimeout(1625, function () {
|
connection.setTimeout(1620, function () {
|
||||||
if (!exiting) SVRJSFork();
|
if (!exiting) SVRJSFork();
|
||||||
crashed = true;
|
crashed = true;
|
||||||
});
|
});
|
||||||
|
@ -5173,7 +5173,7 @@ function start(init) {
|
||||||
"X-SVR-JS-From-Main-Thread": "true",
|
"X-SVR-JS-From-Main-Thread": "true",
|
||||||
"User-Agent": (exposeServerVersion ? "SVR.JS/" + version + " (" + getOS() + "; " + (process.isBun ? ("Bun/v" + process.versions.bun + "; like Node.JS/" + process.version) : ("Node.JS/" + process.version)) + ")" : "SVR.JS")
|
"User-Agent": (exposeServerVersion ? "SVR.JS/" + version + " (" + getOS() + "; " + (process.isBun ? ("Bun/v" + process.versions.bun + "; like Node.JS/" + process.version) : ("Node.JS/" + process.version)) + ")" : "SVR.JS")
|
||||||
},
|
},
|
||||||
timeout: 1625
|
timeout: 1620
|
||||||
}, function (res) {
|
}, function (res) {
|
||||||
chksocket.removeAllListeners("timeout");
|
chksocket.removeAllListeners("timeout");
|
||||||
res.destroy();
|
res.destroy();
|
||||||
|
@ -5191,7 +5191,7 @@ function start(init) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 4500);
|
}, 4550);
|
||||||
|
|
||||||
// Termination of unused good workers
|
// Termination of unused good workers
|
||||||
if(cluster.isPrimary !== undefined) {
|
if(cluster.isPrimary !== undefined) {
|
||||||
|
@ -5200,11 +5200,7 @@ function start(init) {
|
||||||
if (!closedMaster && !exiting) {
|
if (!closedMaster && !exiting) {
|
||||||
var allClusters = Object.keys(cluster.workers);
|
var allClusters = Object.keys(cluster.workers);
|
||||||
var minClusters = 0;
|
var minClusters = 0;
|
||||||
if(cpus < 8) {
|
minClusters = Math.ceil(cpus * 0.625);
|
||||||
minClusters = Math.ceil(cpus * 0.65);
|
|
||||||
} else {
|
|
||||||
minClusters = Math.ceil(cpus * 0.55);
|
|
||||||
}
|
|
||||||
if(minClusters < 2) minClusters = 2;
|
if(minClusters < 2) minClusters = 2;
|
||||||
var goodWorkers = [];
|
var goodWorkers = [];
|
||||||
function checkWorker(callback, _id) {
|
function checkWorker(callback, _id) {
|
||||||
|
|
Reference in a new issue