feat: Improved Java parameter calculation

This commit is contained in:
Radek Goláň jr. 2024-08-25 08:36:31 +02:00
parent b6b72ede02
commit c14897d33e
Signed by: shield
GPG Key ID: D86423BFC31F3591

View File

@ -1,11 +1,34 @@
#!/bin/sh
set -ex
# Caluclate Memory Limit from cgroups/maxmemory
MEMSIZE=$(grep MemTotal /proc/meminfo | awk '{print $2 * 1024}')
MEMLIMIT=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes)
MEMLIMIT=$((MEMLIMIT<MEMSIZE ? MEMLIMIT : MEMSIZE))
MEMOFFSET=1073741824
MEMOFFSET_THRESH=4294967296
G1PARAM_THRESH=12884901888
# Offset memory for Java by 1-1.5G depending on memory available
if [ $MEMLIMIT -lt $MEMOFFSET_THRESH ]; then
MEMOFFSET=1073741824
else
MEMOFFSET=1610612736
fi
SERVER_MEM=$((MEMLIMIT-MEMOFFSET))
# Configure G1 parameters based on Java memory limits
if [ $SERVER_MEM -lt $G1PARAM_THRESH ]; then
G1NEWSIZE=30
G1MAXNEWSIZE=40
G1HEAP=8M
else
G1NEWSIZE=40
G1MAXNEWSIZE=50
G1HEAP=16M
fi
if [ -e "/server/modpack.json" ]; then
mrpack-install --server-dir /server --server-file server.jar update "$@" <<EOF
y
@ -20,8 +43,8 @@ cat eula.txt
java -Xms$SERVER_MEM -Xmx$SERVER_MEM -XX:+UseG1GC \
-XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 \
-XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC \
-XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 \
-XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M \
-XX:+AlwaysPreTouch -XX:G1NewSizePercent=$G1NEWSIZE \
-XX:G1MaxNewSizePercent=$G1MAXNEWSIZE -XX:G1HeapRegionSize=$G1HEAP \
-XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 \
-XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 \
-XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 \