docker-minecraft-server icon indicating copy to clipboard operation
docker-minecraft-server copied to clipboard

Provide a clearer way to request JVM to derive memory limit percentages

Open itzg opened this issue 3 years ago • 2 comments

Enhancement Type

Improve an existing feature

Describe the enhancement

As observed in #1512 , the unsetting of MEMORY with an empty string is an awkward and brittle way of saying "I would like the JVM to derive heap limits from the host/container".

I would like to instead introduce the new variables:

  • MEMORY_PCT
  • MAX_MEMORY_PCT, defaults to MEMORY_PCT
  • MIN_MEMORY_PCT, defaults to MEMORY_PCT

That will indicate MEMORY and co be ignored, but also add the JVM args, such as -XX:MaxRAMPercentage=75

itzg avatar May 11 '22 13:05 itzg

@itzg This is easy to add in start-finalExec, but the real question is how do you want this to be triggered? Do we want to replace MEMORY with MEMORY_PCT? I can't imagine as it is probably widely in use. 🤔 Really this is more in how we'd want to handle memory_pct vs min and max. Thoughts?

if [ ! "${MEMORY}" ]; then
  MIN_MEMORY_PCT=$([ "$MIN_MEMORY_PCT" ] && echo "$MIN_MEMORY_PCT" || echo "$MEMORY_PCT")
  MAX_MEMORY_PCT=$([ "$MAX_MEMORY_PCT" ] && echo "$MAX_MEMORY_PCT" || echo "$MEMORY_PCT")
  JVM_XX_OPTS="${JVM_XX_OPTS}
  -XX:MinRAMPercentage=${MIN_MEMORY_PCT}
  -XX:MaxRAMPercentage=${MAX_MEMORY_PCT}
  "
fi

shotah avatar Oct 19 '22 17:10 shotah

To reword what I meant in the description: if any of the "PCT" variables are set, then the MEMORY variables are ignored. Otherwise, MEMORY variables remain working as always.

I was just expecting the usual fallback variable mechanism like

: "${MIN_MEMORY_PCT:=${MEMORY_PCT:-25}}"

and then say 95 for the final fallback for max pct.

itzg avatar Oct 20 '22 02:10 itzg