Chunk Pregeneration and VM Capacity Planning
Changes to chunk pregeneration, heap, VM, and distance settings, with their effects left unmeasured separately
Whenever the server I ran with friends became sluggish, I increased the Java heap, reduced the area processed around players, and upgraded the VM. The heap grew from 1GB to 8GB, and I applied the Aikar flags described by Paper as a bundle. I changed view-distance and simulation-distance several times based on how the game felt while connected.
The server became playable again, but I did not measure the effect of each change separately. Heap, VM capacity, chunk generation, and distance settings changed around the same period. This article separates the work each setting affects and identifies measurements for a future test.
From a 1GB Heap to Aikar Flags
Heap and server capacity changed in this order.
| Date | Java and heap | Other changes |
|---|---|---|
| 2025-05-20 | Java 22, Xms1G/Xmx1G | Initial Minecraft 1.21.4 run |
| 2025-06-02 | Xms4G/Xmx6G | Added G1GC and pause-related options |
| 2025-06-04 | Java 21.0.7, Xms6G/Xmx6G | Applied 20 Aikar-style flags |
| 2025-06-23 | Xms6G/Xmx6G | Expanded VM from 2 vCPU/8GB to 4 vCPU/16GB |
| 2025-06-25 | Xms8G/Xmx8G | Expanded heap after the VM memory upgrade |
In early June I applied the following options together.
-Xms6G -Xmx6G
-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
This matches the Aikar configuration introduced in the Paper documentation, excluding its identifying -D options. I applied all twenty because they were widely recommended for Minecraft servers. That left no separate comparison showing which option affected GC pauses or throughput.
Three Options That Reserve Heap Early
Xms sets the initial heap and Xmx its maximum. Initially the heap could start at 4GB and grow to 6GB; two days later I fixed both at 6GB. With AlwaysPreTouch, the JVM touches heap pages at startup. This can move some first-touch and heap-expansion cost out of normal execution, while increasing startup time and initial memory use.
This server had to boot and recover Minecraft readiness after preemption. Xms=Xmx and pre-touch could reduce variation during ticks while delaying recovery. I did not compare time to Done (...) before and after enabling pre-touch.
Options That Restrict G1’s Automatic Tuning
G1 is the default collector on server-class machines in Java 21. Explicitly setting UseG1GC documents that choice; it does not by itself establish a change from the default. MaxGCPauseMillis=200 is a target G1 uses to adjust its work, rather than a hard limit.
Other options fix values that G1 would otherwise choose.
G1NewSizePercent=30andG1MaxNewSizePercent=40bound the young generation.G1HeapRegionSize=8Mfixes heap-region size.G1ReservePercent,G1HeapWastePercent, andG1MixedGCCountTargetaffect reserve space and mixed-collection work.InitiatingHeapOccupancyPercent=15encourages marking to start early.SurvivorRatio=32andMaxTenuringThreshold=1affect movement through survivor space and into the old generation.
These values form a bundle intended for a workload. Oracle’s Java 21 G1 guide instead recommends starting from defaults and adjusting heap size and the pause target when necessary. It specifically warns that fixing young-generation size restricts G1’s ability to meet pause targets. I should have used GC logs to check whether the individual Aikar values suited my server.
DisableExplicitGC ignores System.gc() requests from the application or plugins. PerfDisableSharedMem disables shared memory used by HotSpot performance counters. The first can prevent unnecessary explicit collection; the second can also affect data used by JVM observation tools. Observability belongs in that choice too.
A 16GB VM and an 8GB Heap
As load grew, I changed the VM from e2-standard-2 to n2-standard-4: from 2 vCPU/8GB to 4 vCPU/16GB. Two days later I increased the Java heap from 6GB to 8GB.
The VM’s entire memory cannot go to heap. An 8GB VM with Xmx8G leaves no budget for Java’s non-heap memory or the operating system. The VM memory budget must come first.
flowchart LR
accTitle: Minecraft VM memory budget
accDescr: Xmx and GC headroom derived from the live heap, Java non-heap memory, operating-system and page-cache use, and concurrent work all contribute to the VM budget.
subgraph JAVA["Java process"]
direction TB
LIVE[Heap live set under load] --> XMX[Xmx and GC headroom]
NATIVE[Outside the heap<br/>native · threads · buffers]
end
subgraph SHARED["Other uses on the same VM"]
direction TB
HOST[Linux · guest agent<br/>page cache]
SIDE[Discord bot · backups<br/>Chunky · Dynmap]
end
XMX --> VM[Required VM memory]
NATIVE --> VM
HOST --> VM
SIDE --> VM
Beyond Xmx, Java uses memory for metaspace, thread stacks, the JIT code cache, direct buffers, and GC structures. Linux, the Google guest agent, the Discord bot, backup compression, and filesystem page cache also consume memory on this VM.
Some important Minecraft tick work concentrates on one thread. Doubling vCPUs gives Chunky workers, GC, networking, and other processes more room, but does not make the main tick thread proportionally faster. Thread-level CPU and MSPT are better evidence for the upgrade than whole-VM CPU averages alone.
View Distance and Simulation Distance
The two distances in server.properties affect different work.
| Setting | Values used | Main work affected |
|---|---|---|
view-distance | 14 → 12 → 10 → 14 | World area sent to and maintained for players |
simulation-distance | 14 → 6 → 7 | Area ticked around players |
network-compression-threshold | 64 → 256 | Packet size at which compression begins |
View distance is a radius around each player. Other things equal, candidate chunks and retained data grow with area. Players share overlapping regions and already loaded chunks, so (2d+1)² × player count is not the actual loaded-chunk count.
Within simulation distance, entities, blocks, and other game systems keep ticking. Reducing it from 14 to 6 targeted the actively updated area. I later raised it to 7 based on how play felt.
Raising the compression threshold from 64 to 256 bytes removes packets of 64–255 bytes from compression. It can reduce CPU spent compressing small packets while increasing traffic. Without measuring network headroom and the CPU bottleneck, I cannot say which tradeoff was better.
flowchart LR accTitle: Server work affected by player-distance settings accDescr: Client transmission and server tick processing branch from the player position and are limited by view and tracking settings, or simulation and activation settings. P[Player position] --> SEND[Client transmission] P --> PROCESS[Server tick processing] SEND --> VIEW[View distance<br/>chunk data] SEND --> TRACK[Tracking range<br/>entity updates] PROCESS --> SIM[Simulation distance<br/>block · entity ticks] PROCESS --> ACTIVE[Activation range<br/>AI · movement]
I reduced view distance from 14 to 12 and then 10 before returning to 14. I tried each while connected, without a TPS/MSPT comparison. The final 14 reflects play preference rather than a measured performance result.
Mob Counts and Entity Processing Ranges
The June 4 change also adjusted values beyond distance.
- Bukkit spawn limits fell from
70 → 40for monsters,10 → 8for animals, and15 → 1for ambient mobs. - Spigot tracking ranges fell from
128 → 48for players,96 → 32for animals and monsters, and96 → 16for miscellaneous entities. - Activation ranges fell from
32 → 16for animals,32 → 24for monsters, and16 → 8for miscellaneous entities.
Lower spawn limits can reduce spawning, AI, and collision work. Entities outside activation range are not processed at the same level every tick; entities outside tracking range are not sent to clients. These changes can reduce CPU and network work while affecting mob-farm output, distant animal movement, and the world players experience. They are gameplay choices as well as performance settings.
Long files such as paper-global.yml, paper-world-defaults.yml, and purpur.yml do not require tuning every entry. Many values, including worker-threads: -1, io-threads: -1, and region-file-cache-size: 256, were generated defaults. Separating changed values from defaults makes later rollback and comparison possible.
sync-chunk-writes=true sounds like a synchronous-write choice, but the current Paper documentation says it has no effect by default unless a related system property is enabled. use-native-transport=true enables native transport on Linux. A setting’s name or comment cannot establish its performance effect; first check whether that Purpur version actually applied it.
The Cost of a 10,000-Block Radius
To move terrain generation out of friends’ first exploration, I pregenerated a radius of 10,000 blocks with Chunky. Creating 1,565,001 chunks took 15 hours, 53 minutes, and 18 seconds.
10,000 ÷ 16 = 625, so a center-inclusive square has 625 × 2 + 1 = 1,251 chunks per side. 1,251² = 1,565,001; a square scope therefore provides a planning model for that workload.
The following commands illustrate a square scope matching that count. They are not a preserved transcript of every original command. Check the world, shape, and center before running a new job.
/chunky world world
/chunky shape square
/chunky center 0 0
/chunky radius 10000
/chunky start
The overall average across 57,198 seconds was about 27.36 chunks/s. That compares total work and duration, but hides pauses, GC, Dynmap rendering, and player sessions during the run.
flowchart LR accTitle: Costs created by chunk pregeneration scope accDescr: Radius and shape determine chunk count, which creates runtime resource costs and later data costs, including tick competition, region writes, backups, and restoration. SCOPE[Radius · shape<br/>chunk count] --> RUN[Runtime cost] SCOPE --> DATA[Generated data] RUN --> CPU[Terrain · lighting<br/>tick competition] RUN --> IO[Region writes<br/>execution time] DATA --> BACKUP[World size<br/>backup · upload] DATA --> RESTORE[Storage capacity<br/>restore time]
Doubling the radius under the same shape roughly quadruples area. A square is about 4/π, or 27%, larger than a circle of the same radius. Pregeneration shifts first-generation work to a quiet period, while paying CPU, disk-write, world-size, and future backup costs in advance.
Questions Left After the Warnings Stopped
Logs from the slowest period contained many Can't keep up warnings.
| Date | Lines matching Can't keep up | Lines matching memory errors |
|---|---|---|
| 2025-06-20 | 5 | 0 |
| 2025-06-21 | 2 | 0 |
| 2025-06-22 | 603 | 0 |
| 2025-06-23 | 649 | 0 |
| 2025-06-24 | 0 | 0 |
| 2025-06-25 | 0 | 0 |
Chunky and Dynmap ran together on June 22–23; VM and heap increases followed. The sampled logs had no matching warnings from June 24 onward, but I did not collect MSPT, GC pauses, per-core CPU, and disk latency together. Improvement alone cannot identify the effective change.
This experience does not establish that:
- Chunky or Dynmap alone caused all 1,252 matching warnings.
- The VM upgrade or heap increase alone removed later warnings.
- An OOM caused the heap increase.
- Aikar flags reduced pauses.
I did not experience an OOM then. Expanding capacity because memory headroom worried me is different from a server exiting for lack of memory.
The Name of /gc
The Discord bot ran gc through RCON about every five minutes. Its name suggests forced JVM garbage collection, but the bot parsed uptime, TPS, and maximum, allocated, and free memory from the response to build server information and charts.
EssentialsX’s gc reports memory, uptime, and tick information without calling System.gc(). Before treating it as a conflict with DisableExplicitGC, identify the plugin handling the command and inspect its output.
A Sequence for the Next Load Test
I would start with a small radius and retain the following timeline.
| Phase | Work | Measurements kept alongside it |
|---|---|---|
| baseline | Normal operation without players | TPS/MSPT, heap/RSS, thread CPU, disk latency |
| warm-up | Start Chunky at a small radius | CPS, GC cycles/pauses, per-core CPU |
| load | Test players move and build | Tail MSPT, status latency, player events |
| pause | /chunky pause | Time for queues and resources to return to baseline |
| tune | Change one setting and repeat | Difference under the same world, version, and scope |
minecraft-server.service below is an example unit name. Replace it with the unit verified on your server.
pid=$(systemctl show --property MainPID --value minecraft-server.service)
pidstat -p "$pid" -t 10
vmstat 10
iostat -xz 10
jcmd "$pid" GC.heap_info
Add rotating GC logs using Java 21 startup-option syntax.
-Xlog:gc*:logs/gc.log:time,uptime:filecount=5,filesize=10M
If Native Memory Tracking is needed, first check its startup options and overhead in a test environment. Keep spark profiles, TPS, and MSPT with matching timestamps. Changing heap, VM, view distance, and mob limits separately is necessary to compare their effects.
For each run, record server, Java, and plugin versions; VM and disk specifications; JVM options; and the Chunky scope. Identify worlds with publishable aliases rather than seeds. Group start/end times, pause counts, resource use, world-size changes, and backup duration under the same run. That makes a comparison with the historical 27.36 CPS meaningful under matching conditions.
Disk planning also needs peak use, rather than free space at completion. After pregeneration, a backup can temporarily require all of the following.
peak local bytes
= live world
+ backup working copy
+ compressed archive
+ growth during the operation
+ filesystem headroom
I changed several values together to reopen the server quickly. Friends could play again, but the changes did not leave a reusable, measured optimization method. Next time I would build a small load test and change one setting at a time before adding more G1 flags.
References
- PaperMC: Aikar flags and memory
- PaperMC: server.properties
- PaperMC: Global configuration
- PaperMC: spigot.yml
- Oracle Java 21: G1 tuning
- Oracle Java 21: java command options
- EssentialsX:
gccommand description - Chunky: Pregeneration
- spark: Minecraft performance profiler
- Google Cloud: General-purpose machine families
Comments
No comments yet. Be the first to leave one.
Pending review