Symptoms: A lag spike every few seconds, the server freezes, periodic stuttering
Possible Causes
- Garbage Collection pauses
- Automatic saving (autosave)
- Chunk generation load
- Bad JVM flags
Step-by-Step Fix
Step 1
Use Aikar's JVM flags
java -Xms10G -Xmx10G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -jar server.jar noguiStep 2
Pre-generate the world
/chunky radius 5000
/chunky startStep 3
Run a GC analysis with the Spark profiler
/spark gcStep 4
Increase the autosave interval (paper.yml)
max-auto-save-chunks-per-tick: 8