Enhanced Aikar's flag logic to adjust for >12GB memory

For #483
This commit is contained in:
Geoff Bourne 2020-04-11 10:41:20 -05:00
parent 7910005086
commit cd70cbcbea
3 changed files with 53 additions and 9 deletions

View file

@ -1042,10 +1042,16 @@ To enable remote JMX, such as for profiling with VisualVM or JMC, add the enviro
### Enable Aikar's Flags
[Aikar has does some research](https://aikar.co/2018/07/02/tuning-the-jvm-g1gc-garbage-collector-flags-for-minecraft/) into finding the optimal JVM flags for GC tuning, which becomes more important as more users are connected concurrently. The set of flags documented there can be added using
[Aikar has does some research](https://mcflags.emc.gs/) into finding the optimal JVM flags for GC tuning, which becomes more important as more users are connected concurrently. The set of flags documented there can be added using
-e USE_AIKAR_FLAGS=true
When `MEMORY` is greater than or equal to 12G, then the Aikar flags will be adjusted according to the article.
Large page support can also be enabled by adding
-e USE_LARGE_PAGES=true
### HTTP Proxy
You may configure the use of an HTTP/HTTPS proxy by passing the proxy's URL via the `PROXY`

View file

@ -115,22 +115,39 @@ if isTrue ${ENABLE_JMX}; then
log "JMX is enabled. Make sure you have port forwarding for ${JMX_PORT}"
fi
if isTrue ${USE_AIKAR_FLAGS}; then
# From https://aikar.co/2018/07/02/tuning-the-jvm-g1gc-garbage-collector-flags-for-minecraft/
JVM_OPTS="${JVM_XX_OPTS}
if isTrue "${USE_AIKAR_FLAGS}"; then
# From https://mcflags.emc.gs/
if (( $(normalizeMemSize "${MAX_MEMORY}") >= $(normalizeMemSize 12g) )); then
log "Using Aikar's >12GB flags"
G1NewSizePercent=40
G1MaxNewSizePercent=50
G1HeapRegionSize=16M
G1ReservePercent=15
InitiatingHeapOccupancyPercent=20
else
log "Using Aikar's flags"
G1NewSizePercent=30
G1MaxNewSizePercent=40
G1HeapRegionSize=8M
G1ReservePercent=20
InitiatingHeapOccupancyPercent=15
fi
JVM_XX_OPTS="${JVM_XX_OPTS}
-XX:+UseG1GC -XX:+ParallelRefProcEnabled
-XX:MaxGCPauseMillis=200
-XX:+UnlockExperimentalVMOptions
-XX:+DisableExplicitGC
-XX:-OmitStackTraceInFastThrow
-XX:+AlwaysPreTouch
-XX:G1NewSizePercent=30
-XX:G1MaxNewSizePercent=40
-XX:G1HeapRegionSize=8M
-XX:G1ReservePercent=20
-XX:G1NewSizePercent=${G1NewSizePercent}
-XX:G1MaxNewSizePercent=${G1MaxNewSizePercent}
-XX:G1HeapRegionSize=${G1HeapRegionSize}
-XX:G1ReservePercent=${G1ReservePercent}
-XX:G1HeapWastePercent=5
-XX:G1MixedGCCountTarget=8
-XX:InitiatingHeapOccupancyPercent=15
-XX:InitiatingHeapOccupancyPercent=${InitiatingHeapOccupancyPercent}
-XX:G1MixedGCLiveThresholdPercent=90
-XX:G1RSetUpdatingPauseTimePercent=5
-XX:SurvivorRatio=32
@ -140,6 +157,12 @@ if isTrue ${USE_AIKAR_FLAGS}; then
"
fi
if isTrue "${USE_LARGE_PAGES}"; then
JVM_XX_OPTS="${JVM_XX_OPTS}
-XX:+UseLargePagesInMetaspace
"
fi
mcServerRunnerArgs="--stop-duration 60s"
if [[ ${TYPE} == "FEED-THE-BEAST" ]]; then

View file

@ -48,3 +48,18 @@ function logn {
function log {
echo "[init] $*"
}
function normalizeMemSize {
local scale=1
case ${1,,} in
*k)
scale=1024;;
*m)
scale=1048576;;
*g)
scale=1073741824;;
esac
val=${1:0: -1}
echo $(( val * scale ))
}