Server specific ram.
This commit is contained in:
parent
3ef5fabb35
commit
a731fa90ea
@ -1,6 +1,5 @@
|
|||||||
const fs = require('fs-extra')
|
const fs = require('fs-extra')
|
||||||
const { LoggerUtil } = require('helios-core')
|
const { LoggerUtil } = require('helios-core')
|
||||||
const { mcVersionAtLeast } = require('helios-core/common')
|
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
@ -45,24 +44,30 @@ const configPath = path.join(exports.getLauncherDirectory(), 'config.json')
|
|||||||
const configPathLEGACY = path.join(dataPath, 'config.json')
|
const configPathLEGACY = path.join(dataPath, 'config.json')
|
||||||
const firstLaunch = !fs.existsSync(configPath) && !fs.existsSync(configPathLEGACY)
|
const firstLaunch = !fs.existsSync(configPath) && !fs.existsSync(configPathLEGACY)
|
||||||
|
|
||||||
exports.getAbsoluteMinRAM = function(){
|
exports.getAbsoluteMinRAM = function(ram){
|
||||||
|
if(ram?.minimum != null) {
|
||||||
|
return ram.minimum/1024
|
||||||
|
} else {
|
||||||
|
// Legacy behavior
|
||||||
const mem = os.totalmem()
|
const mem = os.totalmem()
|
||||||
return mem >= 6000000000 ? 3 : 2
|
return mem >= (6*1073741824) ? 3 : 2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getAbsoluteMaxRAM = function(){
|
exports.getAbsoluteMaxRAM = function(ram){
|
||||||
const mem = os.totalmem()
|
const mem = os.totalmem()
|
||||||
const gT16 = mem-16000000000
|
const gT16 = mem-(16*1073741824)
|
||||||
return Math.floor((mem-1000000000-(gT16 > 0 ? (Number.parseInt(gT16/8) + 16000000000/4) : mem/4))/1000000000)
|
return Math.floor((mem-(gT16 > 0 ? (Number.parseInt(gT16/8) + (16*1073741824)/4) : mem/4))/1073741824)
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveMaxRAM(){
|
function resolveSelectedRAM(ram) {
|
||||||
|
if(ram?.recommended != null) {
|
||||||
|
return `${ram.recommended}M`
|
||||||
|
} else {
|
||||||
|
// Legacy behavior
|
||||||
const mem = os.totalmem()
|
const mem = os.totalmem()
|
||||||
return mem >= 8000000000 ? '4G' : (mem >= 6000000000 ? '3G' : '2G')
|
return mem >= (8*1073741824) ? '4G' : (mem >= (6*1073741824) ? '3G' : '2G')
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveMinRAM(){
|
|
||||||
return resolveMaxRAM()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -503,18 +508,18 @@ exports.setModConfiguration = function(serverid, configuration){
|
|||||||
|
|
||||||
// Java Settings
|
// Java Settings
|
||||||
|
|
||||||
function defaultJavaConfig(mcVersion) {
|
function defaultJavaConfig(effectiveJavaOptions, ram) {
|
||||||
if(mcVersionAtLeast('1.17', mcVersion)) {
|
if(effectiveJavaOptions.suggestedMajor > 8) {
|
||||||
return defaultJavaConfig117()
|
return defaultJavaConfig17(ram)
|
||||||
} else {
|
} else {
|
||||||
return defaultJavaConfigBelow117()
|
return defaultJavaConfig8(ram)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function defaultJavaConfigBelow117() {
|
function defaultJavaConfig17(ram) {
|
||||||
return {
|
return {
|
||||||
minRAM: resolveMinRAM(),
|
minRAM: resolveSelectedRAM(ram),
|
||||||
maxRAM: resolveMaxRAM(), // Dynamic
|
maxRAM: resolveSelectedRAM(ram),
|
||||||
executable: null,
|
executable: null,
|
||||||
jvmOptions: [
|
jvmOptions: [
|
||||||
'-XX:+UseConcMarkSweepGC',
|
'-XX:+UseConcMarkSweepGC',
|
||||||
@ -525,10 +530,10 @@ function defaultJavaConfigBelow117() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function defaultJavaConfig117() {
|
function defaultJavaConfig8(ram) {
|
||||||
return {
|
return {
|
||||||
minRAM: resolveMinRAM(),
|
minRAM: resolveSelectedRAM(ram),
|
||||||
maxRAM: resolveMaxRAM(), // Dynamic
|
maxRAM: resolveSelectedRAM(ram),
|
||||||
executable: null,
|
executable: null,
|
||||||
jvmOptions: [
|
jvmOptions: [
|
||||||
'-XX:+UnlockExperimentalVMOptions',
|
'-XX:+UnlockExperimentalVMOptions',
|
||||||
@ -547,9 +552,9 @@ function defaultJavaConfig117() {
|
|||||||
* @param {string} serverid The server id.
|
* @param {string} serverid The server id.
|
||||||
* @param {*} mcVersion The minecraft version of the server.
|
* @param {*} mcVersion The minecraft version of the server.
|
||||||
*/
|
*/
|
||||||
exports.ensureJavaConfig = function(serverid, mcVersion) {
|
exports.ensureJavaConfig = function(serverid, effectiveJavaOptions, ram) {
|
||||||
if(!Object.prototype.hasOwnProperty.call(config.javaConfig, serverid)) {
|
if(!Object.prototype.hasOwnProperty.call(config.javaConfig, serverid)) {
|
||||||
config.javaConfig[serverid] = defaultJavaConfig(mcVersion)
|
config.javaConfig[serverid] = defaultJavaConfig(effectiveJavaOptions, ram)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ async function initSettingsValues(){
|
|||||||
if(cVal === 'MinRAM' || cVal === 'MaxRAM'){
|
if(cVal === 'MinRAM' || cVal === 'MaxRAM'){
|
||||||
let val = gFn.apply(null, gFnOpts)
|
let val = gFn.apply(null, gFnOpts)
|
||||||
if(val.endsWith('M')){
|
if(val.endsWith('M')){
|
||||||
val = Number(val.substring(0, val.length-1))/1000
|
val = Number(val.substring(0, val.length-1))/1024
|
||||||
} else {
|
} else {
|
||||||
val = Number.parseFloat(val)
|
val = Number.parseFloat(val)
|
||||||
}
|
}
|
||||||
@ -1158,16 +1158,6 @@ const settingsJavaExecDetails = document.getElementById('settingsJavaExecDetails
|
|||||||
const settingsJavaReqDesc = document.getElementById('settingsJavaReqDesc')
|
const settingsJavaReqDesc = document.getElementById('settingsJavaReqDesc')
|
||||||
const settingsJvmOptsLink = document.getElementById('settingsJvmOptsLink')
|
const settingsJvmOptsLink = document.getElementById('settingsJvmOptsLink')
|
||||||
|
|
||||||
// Store maximum memory values.
|
|
||||||
const SETTINGS_MAX_MEMORY = ConfigManager.getAbsoluteMaxRAM()
|
|
||||||
const SETTINGS_MIN_MEMORY = ConfigManager.getAbsoluteMinRAM()
|
|
||||||
|
|
||||||
// Set the max and min values for the ranged sliders.
|
|
||||||
settingsMaxRAMRange.setAttribute('max', SETTINGS_MAX_MEMORY)
|
|
||||||
settingsMaxRAMRange.setAttribute('min', SETTINGS_MIN_MEMORY)
|
|
||||||
settingsMinRAMRange.setAttribute('max', SETTINGS_MAX_MEMORY)
|
|
||||||
settingsMinRAMRange.setAttribute('min', SETTINGS_MIN_MEMORY )
|
|
||||||
|
|
||||||
// Bind on change event for min memory container.
|
// Bind on change event for min memory container.
|
||||||
settingsMinRAMRange.onchange = (e) => {
|
settingsMinRAMRange.onchange = (e) => {
|
||||||
|
|
||||||
@ -1178,7 +1168,7 @@ settingsMinRAMRange.onchange = (e) => {
|
|||||||
// Get reference to range bar.
|
// Get reference to range bar.
|
||||||
const bar = e.target.getElementsByClassName('rangeSliderBar')[0]
|
const bar = e.target.getElementsByClassName('rangeSliderBar')[0]
|
||||||
// Calculate effective total memory.
|
// Calculate effective total memory.
|
||||||
const max = (os.totalmem()-1000000000)/1000000000
|
const max = os.totalmem()/1073741824
|
||||||
|
|
||||||
// Change range bar color based on the selected value.
|
// Change range bar color based on the selected value.
|
||||||
if(sMinV >= max/2){
|
if(sMinV >= max/2){
|
||||||
@ -1210,7 +1200,7 @@ settingsMaxRAMRange.onchange = (e) => {
|
|||||||
// Get reference to range bar.
|
// Get reference to range bar.
|
||||||
const bar = e.target.getElementsByClassName('rangeSliderBar')[0]
|
const bar = e.target.getElementsByClassName('rangeSliderBar')[0]
|
||||||
// Calculate effective total memory.
|
// Calculate effective total memory.
|
||||||
const max = (os.totalmem()-1000000000)/1000000000
|
const max = os.totalmem()/1073741824
|
||||||
|
|
||||||
// Change range bar color based on the selected value.
|
// Change range bar color based on the selected value.
|
||||||
if(sMaxV >= max/2){
|
if(sMaxV >= max/2){
|
||||||
@ -1338,8 +1328,8 @@ function updateRangedSlider(element, value, notch){
|
|||||||
* Display the total and available RAM.
|
* Display the total and available RAM.
|
||||||
*/
|
*/
|
||||||
function populateMemoryStatus(){
|
function populateMemoryStatus(){
|
||||||
settingsMemoryTotal.innerHTML = Number((os.totalmem()-1000000000)/1000000000).toFixed(1) + 'G'
|
settingsMemoryTotal.innerHTML = Number((os.totalmem()-1073741824)/1073741824).toFixed(1) + 'G'
|
||||||
settingsMemoryAvail.innerHTML = Number(os.freemem()/1000000000).toFixed(1) + 'G'
|
settingsMemoryAvail.innerHTML = Number(os.freemem()/1073741824).toFixed(1) + 'G'
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1360,15 +1350,12 @@ async function populateJavaExecDetails(execPath){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Update to use semver range
|
function populateJavaReqDesc(server) {
|
||||||
async function populateJavaReqDesc() {
|
|
||||||
const server = (await DistroAPI.getDistribution()).getServerById(ConfigManager.getSelectedServer())
|
|
||||||
settingsJavaReqDesc.innerHTML = `Requires Java ${server.effectiveJavaOptions.suggestedMajor} x64.`
|
settingsJavaReqDesc.innerHTML = `Requires Java ${server.effectiveJavaOptions.suggestedMajor} x64.`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Update to use semver range
|
// TODO Update to use semver range
|
||||||
async function populateJvmOptsLink() {
|
function populateJvmOptsLink(server) {
|
||||||
const server = (await DistroAPI.getDistribution()).getServerById(ConfigManager.getSelectedServer())
|
|
||||||
const major = server.effectiveJavaOptions.suggestedMajor
|
const major = server.effectiveJavaOptions.suggestedMajor
|
||||||
settingsJvmOptsLink.innerHTML = `Available Options for Java ${major} (HotSpot VM)`
|
settingsJvmOptsLink.innerHTML = `Available Options for Java ${major} (HotSpot VM)`
|
||||||
if(major >= 12) {
|
if(major >= 12) {
|
||||||
@ -1385,14 +1372,28 @@ async function populateJvmOptsLink() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bindMinMaxRam(server) {
|
||||||
|
// Store maximum memory values.
|
||||||
|
const SETTINGS_MAX_MEMORY = ConfigManager.getAbsoluteMaxRAM(server.rawServer.javaOptions?.ram)
|
||||||
|
const SETTINGS_MIN_MEMORY = ConfigManager.getAbsoluteMinRAM(server.rawServer.javaOptions?.ram)
|
||||||
|
|
||||||
|
// Set the max and min values for the ranged sliders.
|
||||||
|
settingsMaxRAMRange.setAttribute('max', SETTINGS_MAX_MEMORY)
|
||||||
|
settingsMaxRAMRange.setAttribute('min', SETTINGS_MIN_MEMORY)
|
||||||
|
settingsMinRAMRange.setAttribute('max', SETTINGS_MAX_MEMORY)
|
||||||
|
settingsMinRAMRange.setAttribute('min', SETTINGS_MIN_MEMORY)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare the Java tab for display.
|
* Prepare the Java tab for display.
|
||||||
*/
|
*/
|
||||||
async function prepareJavaTab(){
|
async function prepareJavaTab(){
|
||||||
bindRangeSlider()
|
const server = (await DistroAPI.getDistribution()).getServerById(ConfigManager.getSelectedServer())
|
||||||
|
bindMinMaxRam(server)
|
||||||
|
bindRangeSlider(server)
|
||||||
populateMemoryStatus()
|
populateMemoryStatus()
|
||||||
await populateJavaReqDesc()
|
populateJavaReqDesc(server)
|
||||||
await populateJvmOptsLink()
|
populateJvmOptsLink(server)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -234,7 +234,7 @@ function ensureJavaSettings(data) {
|
|||||||
|
|
||||||
// Nothing too fancy for now.
|
// Nothing too fancy for now.
|
||||||
for(const serv of data.servers){
|
for(const serv of data.servers){
|
||||||
ConfigManager.ensureJavaConfig(serv.rawServer.id, serv.rawServer.minecraftVersion)
|
ConfigManager.ensureJavaConfig(serv.rawServer.id, serv.effectiveJavaOptions, serv.rawServer.javaOptions?.ram)
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigManager.save()
|
ConfigManager.save()
|
||||||
|
Loading…
Reference in New Issue
Block a user