From 29174307b1c4e734c1d4332cb1f2dfc9aac36084 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 26 Jan 2021 18:58:45 +0100 Subject: [PATCH] Fine Tunning Memory Management --- run.js | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/run.js b/run.js index 9848d6d2e..dcea2c68b 100644 --- a/run.js +++ b/run.js @@ -30,52 +30,54 @@ if ( console.log(' minMemo: Optional. Use it when your hardware has less than 8 Gb or memory.') console.log('') console.log('If you are having an error while trying to run this Client, consider this:') - - fatalErrorHelp() + + fatalErrorHelp() return } - -// 9808us Code -- Proposal to improve RAM issues -const os = require("os") -let totalRAM = os.totalmem() // Get total ram installed -totalRAM = totalRAM / 1024 / 1024 +const OS = require("os") +let totalRAM = OS.totalmem() // Get total ram installed +totalRAM = totalRAM / 1024 / 1024 let optimalRAM = totalRAM * 0.85 // Use 85% of installed RAM -let maxOldSpaceSize = "--max-old-space-size="+(optimalRAM.toFixed(0)).toString() +let maxOldSpaceSize = "--max-old-space-size=" + (optimalRAM.toFixed(0)).toString() +let options console.log('') -console.log("Total RAM istalled in this system is: " + totalRAM.toFixed(0)) // Print the result in MB +console.log("Total RAM istalled in this system is ..... " + (totalRAM / 1024).toFixed(2) + " GB") +if (process.argv.includes("minMemo")) { + options = { + stdio: 'inherit' + } + console.log("Total RAM available for Superalgos is .... 512 MB") +} else { + options = { + execArgv: [maxOldSpaceSize], + stdio: 'inherit' + } + console.log("Total RAM available for Superalgos is .... " + (optimalRAM / 1024).toFixed(2) + " GB") + console.log('') + console.log('If you would like to enable less RAM than that, use the minMemo flag. Note: RAM will be allocated only if needed.') +} console.log('') console.log('OPTIONS ACCEPTED:') console.log('') let optionsAccepted = 0 -let options = { - execArgv: [maxOldSpaceSize], - stdio: 'inherit' -} if (process.argv.includes("minMemo")) { - options = { - stdio: 'inherit' - } optionsAccepted++ - console.log('minMemo ............................ Running with Minimun Required Memory') -} else { - console.log('no minMemo configured .............. Running with 85% of installed Memory') - console.log('will use ........................... --max-old-space-size=' + optimalRAM.toFixed(0)) -} + console.log('minMemo ............................ Running with Minimun Required Memory.') +} if (process.argv.includes("noBrowser")) { optionsAccepted++ - console.log('noBrowser .......................... Running without User Interface') + console.log('noBrowser .......................... Running without User Interface.') } if (optionsAccepted === 0) { - console.log('none ............................... Running without any command line options') - console.log('') + console.log('none ............................... Running without any command line options.') } - +console.log('') console.log('') try { @@ -86,7 +88,7 @@ try { console.log('Fail to create Client Process.') console.log('') - fatalErrorHelp() + fatalErrorHelp() } function fatalErrorHelp() {