forked from svrjs/svrjs
Update to SVR.JS 3.15.4
This commit is contained in:
parent
45d8b9bcd3
commit
997b03c2a2
4 changed files with 56 additions and 55 deletions
|
@ -1,7 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>SVR.JS 3.15.3</title>
|
||||
<title>SVR.JS 3.15.4</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta charset="UTF-8" />
|
||||
<style>
|
||||
|
@ -76,7 +76,7 @@
|
|||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to SVR.JS 3.15.3</h1>
|
||||
<h1>Welcome to SVR.JS 3.15.4</h1>
|
||||
<br />
|
||||
<img src="/logo.png" style="width: 224px; max-width: 100%;" />
|
||||
<br />
|
||||
|
@ -148,7 +148,7 @@
|
|||
</code>
|
||||
<p>Changes:</p>
|
||||
<ul style="display: inline-block; margin: 0;">
|
||||
<li>Fixed bug in the URL parser (URLs with "@" got erroneously "sanitized" to "/").</li>
|
||||
<li>Added cap on minimum number of workers to 12 to reduce idle memory usage.</li>
|
||||
</ul>
|
||||
<p>
|
||||
<a href="/tests.html">Tests</a><br />
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>SVR.JS 3.15.3 Licenses</title>
|
||||
<title>SVR.JS 3.15.4 Licenses</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta charset="UTF-8" />
|
||||
<style>
|
||||
|
@ -76,8 +76,8 @@
|
|||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>SVR.JS 3.15.3 Licenses</h1>
|
||||
<h2>SVR.JS 3.15.3</h2>
|
||||
<h1>SVR.JS 3.15.4 Licenses</h1>
|
||||
<h2>SVR.JS 3.15.4</h2>
|
||||
<div style="display: inline-block; text-align: left; border-width: 2px; border-style: solid; border-color: gray; padding: 8px;">
|
||||
MIT License<br/>
|
||||
<br/>
|
||||
|
@ -101,7 +101,7 @@
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE<br/>
|
||||
SOFTWARE.<br/>
|
||||
</div>
|
||||
<h2>Packages used by SVR.JS 3.15.3</h2>
|
||||
<h2>Packages used by SVR.JS 3.15.4</h2>
|
||||
<div style="width: 100%; max-width: 1280px; margin: auto">
|
||||
<div style="width: 100%; background-color: #ccc; background-color: rgba(200, 200, 200, 0.3); border: 1px solid green; text-align: left; margin: 10px 0;">
|
||||
<div style="float: right;">License: MIT</div>
|
||||
|
|
93
svr.js
93
svr.js
|
@ -69,7 +69,7 @@ function deleteFolderRecursive(path) {
|
|||
}
|
||||
|
||||
var os = require("os");
|
||||
var version = "3.15.3";
|
||||
var version = "3.15.4";
|
||||
var singlethreaded = false;
|
||||
|
||||
if (process.versions) process.versions.svrjs = version; // Inject SVR.JS into process.versions
|
||||
|
@ -5320,6 +5320,35 @@ function start(init) {
|
|||
|
||||
|
||||
if (init) {
|
||||
var workersToFork = 1;
|
||||
|
||||
function getWorkerCountToFork() {
|
||||
var workersToFork = os.availableParallelism ? os.availableParallelism() : os.cpus().length;
|
||||
try {
|
||||
var useAvailableCores = Math.round((os.freemem()) / 50000000) - 1; // 1 core deleted for safety...
|
||||
if (workersToFork > useAvailableCores) workersToFork = useAvailableCores;
|
||||
} catch (err) {
|
||||
// Nevermind... Don't want SVR.JS to fail starting, because os.freemem function is not working.
|
||||
}
|
||||
if (workersToFork < 1) workersToFork = 1; // If SVR.JS is run on Haiku (os.cpus in Haiku returns empty array) or if useAvailableCores = 0
|
||||
return workersToFork;
|
||||
}
|
||||
|
||||
function forkWorkers(workersToFork, callback) {
|
||||
for (var i = 0; i < workersToFork; i++) {
|
||||
if (i == 0) {
|
||||
SVRJSFork();
|
||||
} else {
|
||||
setTimeout((function (i) {
|
||||
return function () {
|
||||
SVRJSFork();
|
||||
if (i >= workersToFork - 1) callback();
|
||||
};
|
||||
})(i), i * 6.6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cluster.isPrimary === undefined) {
|
||||
setInterval(function () {
|
||||
try {
|
||||
|
@ -5475,30 +5504,14 @@ function start(init) {
|
|||
if (stopError) serverconsole.climessage("Some SVR.JS workers might not be stopped.");
|
||||
SVRJSInitialized = false;
|
||||
closedMaster = true;
|
||||
var cpus = os.availableParallelism ? os.availableParallelism() : os.cpus().length;
|
||||
try {
|
||||
var useAvailableCores = Math.round((os.freemem()) / 50000000) - 1; // 1 core deleted for safety...
|
||||
if (cpus > useAvailableCores) cpus = useAvailableCores;
|
||||
} catch (err) {
|
||||
// Nevermind... Don't want SVR.JS to fail starting, because os.freemem function is not working.
|
||||
}
|
||||
if (cpus < 1) cpus = 1; // If SVR.JS is running on Haiku or if useAvailableCores = 0
|
||||
for (var i = 0; i < cpus; i++) {
|
||||
if (i == 0) {
|
||||
SVRJSFork();
|
||||
} else {
|
||||
setTimeout((function (i) {
|
||||
return function () {
|
||||
SVRJSFork();
|
||||
if (i >= cpus - 1) {
|
||||
SVRJSInitialized = true;
|
||||
exiting = false;
|
||||
serverconsole.climessage("SVR.JS workers restarted.");
|
||||
}
|
||||
};
|
||||
})(i), i * 6.6);
|
||||
}
|
||||
}
|
||||
|
||||
workersToFork = getWorkerCountToFork();
|
||||
forkWorkers(workersToFork, function () {
|
||||
SVRJSInitialized = true;
|
||||
exiting = false;
|
||||
serverconsole.climessage("SVR.JS workers restarted.");
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
if (command == "stop") {
|
||||
|
@ -5545,26 +5558,11 @@ function start(init) {
|
|||
if (cluster.isPrimary || cluster.isPrimary === undefined) {
|
||||
// Cluster forking code
|
||||
if (cluster.isPrimary !== undefined && init) {
|
||||
var cpus = os.availableParallelism ? os.availableParallelism() : os.cpus().length;
|
||||
try {
|
||||
var useAvailableCores = Math.round((os.freemem()) / 50000000) - 1; // 1 core deleted for safety...
|
||||
if (cpus > useAvailableCores) cpus = useAvailableCores;
|
||||
} catch (err) {
|
||||
// Nevermind... Don't want SVR.JS to fail starting, because os.freemem function is not working.
|
||||
}
|
||||
if (cpus < 1) cpus = 1; // If SVR.JS is run on Haiku (os.cpus in Haiku returns empty array) or if useAvailableCores = 0
|
||||
for (var i = 0; i < cpus; i++) {
|
||||
if (i == 0) {
|
||||
SVRJSFork();
|
||||
} else {
|
||||
setTimeout((function (i) {
|
||||
return function () {
|
||||
SVRJSFork();
|
||||
if (i >= cpus - 1) SVRJSInitialized = true;
|
||||
};
|
||||
})(i), i * 6.6);
|
||||
}
|
||||
}
|
||||
workersToFork = getWorkerCountToFork();
|
||||
forkWorkers(workersToFork, function () {
|
||||
SVRJSInitialized = true;
|
||||
});
|
||||
|
||||
cluster.workers[Object.keys(cluster.workers)[0]].on("message", function (msg) {
|
||||
if (msg.length >= 8 && msg.indexOf("\x12ERRLIST") == 0) {
|
||||
var tries = parseInt(msg.substring(8, 9));
|
||||
|
@ -5675,9 +5673,12 @@ function start(init) {
|
|||
setInterval(function () {
|
||||
if (!closedMaster && !exiting) {
|
||||
var allWorkers = Object.keys(cluster.workers);
|
||||
|
||||
var minWorkers = 0;
|
||||
minWorkers = Math.ceil(cpus * 0.625);
|
||||
minWorkers = Math.ceil(workersToFork * 0.625);
|
||||
if (minWorkers < 2) minWorkers = 2;
|
||||
if (minWorkers > 12) minWorkers = 12;
|
||||
|
||||
var goodWorkers = [];
|
||||
|
||||
function checkWorker(callback, _id) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>SVR.JS 3.15.3 Tests</title>
|
||||
<title>SVR.JS 3.15.4 Tests</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta charset="UTF-8" />
|
||||
<style>
|
||||
|
@ -76,7 +76,7 @@
|
|||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>SVR.JS 3.15.3 Tests</h1>
|
||||
<h1>SVR.JS 3.15.4 Tests</h1>
|
||||
<h2>Directory (without trailing slash)</h2>
|
||||
<iframe src="/testdir" width="75%" height="300px"></iframe>
|
||||
<h2>Directory (with query)</h2>
|
||||
|
|
Reference in a new issue