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>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<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 name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<style>
|
<style>
|
||||||
|
@ -76,7 +76,7 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Welcome to SVR.JS 3.15.3</h1>
|
<h1>Welcome to SVR.JS 3.15.4</h1>
|
||||||
<br />
|
<br />
|
||||||
<img src="/logo.png" style="width: 224px; max-width: 100%;" />
|
<img src="/logo.png" style="width: 224px; max-width: 100%;" />
|
||||||
<br />
|
<br />
|
||||||
|
@ -148,7 +148,7 @@
|
||||||
</code>
|
</code>
|
||||||
<p>Changes:</p>
|
<p>Changes:</p>
|
||||||
<ul style="display: inline-block; margin: 0;">
|
<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>
|
</ul>
|
||||||
<p>
|
<p>
|
||||||
<a href="/tests.html">Tests</a><br />
|
<a href="/tests.html">Tests</a><br />
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<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 name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<style>
|
<style>
|
||||||
|
@ -76,8 +76,8 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>SVR.JS 3.15.3 Licenses</h1>
|
<h1>SVR.JS 3.15.4 Licenses</h1>
|
||||||
<h2>SVR.JS 3.15.3</h2>
|
<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;">
|
<div style="display: inline-block; text-align: left; border-width: 2px; border-style: solid; border-color: gray; padding: 8px;">
|
||||||
MIT License<br/>
|
MIT License<br/>
|
||||||
<br/>
|
<br/>
|
||||||
|
@ -101,7 +101,7 @@
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE<br/>
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE<br/>
|
||||||
SOFTWARE.<br/>
|
SOFTWARE.<br/>
|
||||||
</div>
|
</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%; 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="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>
|
<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 os = require("os");
|
||||||
var version = "3.15.3";
|
var version = "3.15.4";
|
||||||
var singlethreaded = false;
|
var singlethreaded = false;
|
||||||
|
|
||||||
if (process.versions) process.versions.svrjs = version; // Inject SVR.JS into process.versions
|
if (process.versions) process.versions.svrjs = version; // Inject SVR.JS into process.versions
|
||||||
|
@ -5320,6 +5320,35 @@ function start(init) {
|
||||||
|
|
||||||
|
|
||||||
if (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) {
|
if (cluster.isPrimary === undefined) {
|
||||||
setInterval(function () {
|
setInterval(function () {
|
||||||
try {
|
try {
|
||||||
|
@ -5475,30 +5504,14 @@ function start(init) {
|
||||||
if (stopError) serverconsole.climessage("Some SVR.JS workers might not be stopped.");
|
if (stopError) serverconsole.climessage("Some SVR.JS workers might not be stopped.");
|
||||||
SVRJSInitialized = false;
|
SVRJSInitialized = false;
|
||||||
closedMaster = true;
|
closedMaster = true;
|
||||||
var cpus = os.availableParallelism ? os.availableParallelism() : os.cpus().length;
|
|
||||||
try {
|
workersToFork = getWorkerCountToFork();
|
||||||
var useAvailableCores = Math.round((os.freemem()) / 50000000) - 1; // 1 core deleted for safety...
|
forkWorkers(workersToFork, function () {
|
||||||
if (cpus > useAvailableCores) cpus = useAvailableCores;
|
SVRJSInitialized = true;
|
||||||
} catch (err) {
|
exiting = false;
|
||||||
// Nevermind... Don't want SVR.JS to fail starting, because os.freemem function is not working.
|
serverconsole.climessage("SVR.JS workers restarted.");
|
||||||
}
|
});
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (command == "stop") {
|
if (command == "stop") {
|
||||||
|
@ -5545,26 +5558,11 @@ function start(init) {
|
||||||
if (cluster.isPrimary || cluster.isPrimary === undefined) {
|
if (cluster.isPrimary || cluster.isPrimary === undefined) {
|
||||||
// Cluster forking code
|
// Cluster forking code
|
||||||
if (cluster.isPrimary !== undefined && init) {
|
if (cluster.isPrimary !== undefined && init) {
|
||||||
var cpus = os.availableParallelism ? os.availableParallelism() : os.cpus().length;
|
workersToFork = getWorkerCountToFork();
|
||||||
try {
|
forkWorkers(workersToFork, function () {
|
||||||
var useAvailableCores = Math.round((os.freemem()) / 50000000) - 1; // 1 core deleted for safety...
|
SVRJSInitialized = true;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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));
|
||||||
|
@ -5675,9 +5673,12 @@ function start(init) {
|
||||||
setInterval(function () {
|
setInterval(function () {
|
||||||
if (!closedMaster && !exiting) {
|
if (!closedMaster && !exiting) {
|
||||||
var allWorkers = Object.keys(cluster.workers);
|
var allWorkers = Object.keys(cluster.workers);
|
||||||
|
|
||||||
var minWorkers = 0;
|
var minWorkers = 0;
|
||||||
minWorkers = Math.ceil(cpus * 0.625);
|
minWorkers = Math.ceil(workersToFork * 0.625);
|
||||||
if (minWorkers < 2) minWorkers = 2;
|
if (minWorkers < 2) minWorkers = 2;
|
||||||
|
if (minWorkers > 12) minWorkers = 12;
|
||||||
|
|
||||||
var goodWorkers = [];
|
var goodWorkers = [];
|
||||||
|
|
||||||
function checkWorker(callback, _id) {
|
function checkWorker(callback, _id) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<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 name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<style>
|
<style>
|
||||||
|
@ -76,7 +76,7 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>SVR.JS 3.15.3 Tests</h1>
|
<h1>SVR.JS 3.15.4 Tests</h1>
|
||||||
<h2>Directory (without trailing slash)</h2>
|
<h2>Directory (without trailing slash)</h2>
|
||||||
<iframe src="/testdir" width="75%" height="300px"></iframe>
|
<iframe src="/testdir" width="75%" height="300px"></iframe>
|
||||||
<h2>Directory (with query)</h2>
|
<h2>Directory (with query)</h2>
|
||||||
|
|
Reference in a new issue