Optimized Startup Flags for consistent Garbage Collection

These parameters are mot working for my server, I’m running a 6gb 1.12.2 SpongeForge server.
I tried using this Parameters
java -Xms6G -Xmx6G -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:MaxGCPauseMillis=100 -XX:+DisableExplicitGC -XX:TargetSurvivorRatio=90 -XX:G1NewSizePercent=50 -XX:G1MaxNewSizePercent=80 -XX:G1MixedGCLiveThresholdPercent=50 -XX:+AlwaysPreTouch -jar server.jar

And got this as an result.
[Pterodactyl Daemon] Server marked as STARTING

[Pterodactyl Daemon] Checking size of server data directory…

[Pterodactyl Daemon] Disk Usage: 5623M / 20000M

[Pterodactyl Daemon] Ensuring correct ownership of files.

[Pterodactyl Daemon] Running server preflight.

[Pterodactyl Daemon] Starting server container.

openjdk version “1.8.0_242”

OpenJDK Runtime Environment (build 1.8.0_242-b08)

OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)

:/home/container$ java -Xms6G -Xmx6G -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:MaxGCPauseMillis=100 -XX:+DisableExplicitGC -XX:TargetSurvivorRatio=90 -XX:G1NewSizePercent=50 -XX:G1MaxNewSizePercent=80 -XX:G1MixedGCLiveThresholdPercent=50 -XX:+AlwaysPreTouch -jar server.jar

OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000640000000, 6442450944, 0) failed; error=‘Cannot allocate memory’ (errno=12)

There is insufficient memory for the Java Runtime Environment to continue.

Native memory allocation (mmap) failed to map 6442450944 bytes for committing reserved memory.

An error report file with more information is saved as:

/tmp/hs_err_pid35.log

[Pterodactyl Daemon] Server marked as OFF

[Pterodactyl Daemon] ---------- Detected server process in a crashed state! ----------

[Pterodactyl Daemon] Exit Code: 1

[Pterodactyl Daemon] Out of Memory: false

[Pterodactyl Daemon] Error Response:

[Pterodactyl Daemon] Aborting automatic reboot due to crash within the last 60 seconds.

I believe you ended up getting this answered in discord, correct? Server just doesn’t have enough memory for what your trying to allocate.

remove the alwayspretouch flag
docker hates it and allocates everything on startup and causes OOM

Please don’t remove that - It makes performance improvements and is proper… You shouldn’t over provision your servers in just assume that none of them will reach that memory usage.

It literally does not work with ptero, at all. It will always overallocate the memory provided because of how ptero handles jvm flags

That literally makes no sense… containers can allocate themselves as much memory as they want instantly, and I do not know why pterodactyl would have issues with that. The only thing that I can think of is if the host itself has barely enough or not enough memory, in which case of course pterodactyl will start restricting it and then crash it… If you know can you tell me what part of pterodactyl is handling containers differently than what they should?

I don’t know - I just run containers that run Java apps that use almost similar startup arguments but can consume in the hundreds of gigabytes of RAM, and I’ve never run into any of these issues with this. I just see absolutely no reason that it should be causing that style termination.

Edit #2, after looking at that issue, now I’m even more confused lol… The only thing that I can think of is that pterodactyl is allocating and restricting the container to be exactly the memory size that you’re then setting with XMX and XMS - which means that the JVM itself since it actually uses more than XMX is overloading… But then that brings into question why is pterodactyl even putting such a hard restriction on the containers…

They’re one solution of telling pterodactyl to allocate about 500+ megabytes more of memory to the container, then what you’re sending with the JVM arguments should fix this issue, but feels wrong

Reference here: JVM arguments · Issue #1601 · pterodactyl/panel · GitHub

i personally dont know, but thats what their devs are saying

If using -XX:+AlwaysPreTouch allocate 1-2 GB of RAM less for the -Xms flag.
So instead of Xms = Xmx set it to Xms = Xmx - 2 GB

Hi, I’m running a mod server with Pixelmon and I’m trying to solve some constant lag spikes, and consequently a crash due to a tick taking > 60s. After some research and trying to use Aikar’s startup flags, I discovered with Timings that the are some lag spikes interval arround 2-3 minutes and the GC might be the cause.

My question is, in my timings report, using Aikar’s startup flags, there is a red number in G1 Young.
image

What does it mean? Is there a way I could solve it? I noticed that the lag spikes usually occur when chunks are unloading (according to the graphics), would the GC be the cause?

My Timings from weeks ago for reference: Aikar's Timings Viewer

My startup flags:

java -Xms128M -Xmx16000M -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=40 -XX:G1MaxNewSizePercent=50 -XX:G1HeapRegionSize=16M -XX:G1ReservePercent=15 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=20 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar forge-1.12.2-14.23.5.2838-universal.jar

*My server host panel is Pterodactyl and they decided that Xms should be 128M and Xmx should be maximum (16000M) instead of less 1000/1500M as recommended.

Even with -XX:+AlwaysPreTrouch you should keep Xms = Xmx …
So instead of allocating 1-2GB less for Xms and making them mismatch, lower both values, and not just Xms.

You do that on ptero and it crashes with OOM. I think the majority of people here uses ptero panel

Could you please tell me where I can copy and paste these commands? I’ve never run a server before and this is my first time trying. Do I copy and paste it at the top of the server.properties file? Somewhere else? Please help!

These are java start-up arguments. They do no belong in server.properties, they go in the server start-up script. If you have paid hosting, I suggest asking them to assist you. Otherwise; have a read of this:
https://docs.spongepowered.org/stable/en/server/getting-started/launch-script.html

The problem is that the java flags will try to use 1000M - 1500M then what is specified in the Xmx as noted here. By default pterodactyl sets all of the memory allocated to the server to Xmx.

TL;DR
Set the Xmx flag 1000M - 1500M less then what you allocated to the server.