3.5 KiB
3.5 KiB
# JVM Tuning: Optimized G1GC for Minecraft
## Introduction
After extensive research and testing, a set of Garbage Collection flags optimized for Minecraft using the G1GC collector has been developed. These flags ensure consistent server performance with minimal garbage collection spikes, making servers more reliable and stable in terms of TPS (Ticks Per Second).
## Recommended JVM Startup Flags
Use the following flags for Minecraft 1.15 and Java 8+:
```shell
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 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar paperclip.jar nogui
- Note: Adjust
XmxandXmsaccording to your available memory. Do not use all allocated memory to avoid OOM errors.
Memory Recommendations
- Minimum Memory: 6-10GB
- Memory Usage: Leave room for the operating system by not using the full allocated memory.
- For Memory > 12GB: Adjust the following:
-XX:G1NewSizePercent=40-XX:G1MaxNewSizePercent=50-XX:G1HeapRegionSize=16M-XX:G1ReservePercent=15-XX:InitiatingHeapOccupancyPercent=20
Recommended Server Software
Switch to Paper, an optimized version of Spigot:
- Benefits: Performance improvements, bug and exploit fixes, new features, and enhanced API.
Java GC Logging
-
Java 8-10:
-Xloggc:gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=1M -
Java 11+:
-Xlog:gc*:logs/gc.log:time,uptime:filecount=5,filesize=1M
Technical Explanation of the Flags
- -Xms matching -Xmx: Ensure the server can use the entire
-Xmxmemory allocation. - G1NewSizePercent & G1MaxNewSizePercent: Allocate a larger portion of memory to the New Generation for better performance.
- G1MixedGCLiveThresholdPercent: Set to 90 to reclaim old generation garbage quickly.
- G1ReservePercent: Increase to 20 to prevent memory allocation issues.
- MaxTenuringThreshold: Set to 1 to prevent transient data from moving to old generation.
- SurvivorRatio: Set to 32 to free up more regions for Eden.
- AlwaysPreTouch: Ensures memory is contiguous at start-up.
- DisableExplicitGC: Prevents plugins from triggering full garbage collections.
- MaxGCPauseMillis: Controls pause time during collections for minimal TPS impact.
- ParallelRefProcEnabled: Uses multiple threads for weak reference checking.
Changelog
- 5/2/2020: Added
+PerfDisableSharedMem, adjustedMixedGCTargetto 4. - 4/25/2020: Removed
OmitStackTraces. - 4/5/2020: Major refactor of flag suggestions.
- 10/4/2018: Removed
AggressiveOptsandInitiatingHeapOccupancyPercent. - 8/18/2018: Adjusted
MixedGCLiveThresholdto 35.
About Aikar
Daniel Ennis (Aikar) is a Senior Software Engineer and Entrepreneur, passionate about development and community building. He is the founder of Starlis LLC and operates Empire Minecraft.
Copyright © 2007-2025 Aikar's Thoughts - All rights reserved