Fewer crashes and less lag on every server
Free servers were being stopped mid-game, and a CPU setting made ticks stall. Here's what we changed on 29 November, and what changed after.
On 29 November I changed three settings on every server. In the three days before that, 108 free servers were stopped in the middle of a game because they ran out of memory. In the three days after, 3 were. And on a test server with the free plan's limits, the ticks you feel as lag went down to about a third.
None of this changes how the game plays. View distance, mob limits, redstone and farms all work exactly as they did. Here's what was wrong, what I changed, and how I measured it.
Free servers killed for running out of memory
Per day, on all three nodes
Show the numbers
| Day (UTC) | Helsinki node 1 | Helsinki node 2 | London | Total |
|---|---|---|---|---|
| 21 Nov | 13 | 9 | 5 | 27 |
| 22 Nov | 22 | 18 | 7 | 47 |
| 23 Nov | 7 | 5 | 10 | 22 |
| 24 Nov | 8 | 7 | 6 | 21 |
| 25 Nov | 4 | 7 | 7 | 18 |
| 26 Nov | 8 | 3 | 7 | 18 |
| 27 Nov | 19 | 1 | 14 | 34 |
| 28 Nov | 18 | 4 | 24 | 46 |
| 29 Nov | 8 | 1 | 7 | 16 |
| 30 Nov | 1 | 0 | 0 | 1 |
| 1 Dec | 1 | 0 | 0 | 1 |
Why servers were being killed
Every server runs in a box with a memory limit: your plan, plus 1 GB we add on top for Java itself. On a free server that's 2 GB and 1 GB, so 3 GB in total. Java needs that extra room for things that aren't your world, like its own code, threads and network buffers. On real servers I measured between 380 and 810 MB of that.
The old start command let Java use 80% of the box for the world. On a free server that's 2.4 GB, which leaves only about 600 MB for everything else. Often that was fine. When it wasn't, the box went over 3 GB and Linux stopped the server on the spot. There was no save and no error in the console: the log just ended. Your players lost everything since the last autosave. One server's players told us their progress kept resetting every 5 to 10 minutes, and this was why.
Now Java gets exactly your plan for the world, 2 GB on the free plan, and the whole extra 1 GB is left for Java itself. If a server really needs more memory than its plan, it now runs out inside Java, and Java writes an error to the console. Before, it just disappeared.
I don't think this is a lucky week. There were about 13% fewer server starts in the three days after than in the three days before, but kills went from 108 to 3. Kills on bigger plans didn't move (37 before, 29 after), and it isn't zero for free servers either: three still ran out. I'll keep watching it.
Why a server pauses
A Minecraft server works in ticks: 20 a second, so each one has 50 ms. When a tick takes longer than that, the next one starts late, and players notice. Blocks pop back, mobs stutter, and you rubber-band a little.
Your plan also gives your server a share of CPU. On the free plan that's 1.25 cores. Linux keeps servers to their share in windows, and by default a window is 100 ms long. In each window, a free server may use 125 ms of CPU time, spread over all its threads.
That's the catch. A Minecraft server is never just one thread. The main thread runs the tick, and others make new chunks, save the world, send packets and clean up memory. When two or three of them are busy at once, the 125 ms is gone well before the window ends. Then every thread is paused until the next window starts, the main thread too. That pause can last 40 ms or more, in the middle of a tick.
With 10 ms windows, the server gets 12.5 ms of CPU every 10 ms. It's the same amount of CPU in total, but now the longest pause is a few milliseconds instead of most of a tick. Try it below.
Same CPU, different pauses
A tick that needs 20 ms of work, on a server limited to 1.25 cores
There's a small cost. Every tick now gets paused a little, often, instead of most ticks not at all and a few a lot. So the typical tick got slower: in the test below, the middle tick went from about 11 ms to 15 ms. That's still far below 50 ms, so you won't notice it. The slow ticks are the ones players feel.
How I measured it
I set up a test server with exactly the free plan's limits: 2 GB, 1.25 cores, the same box our servers run in, on Paper 26.3. Five players joined and then flew out in all directions at 8 blocks a second for two minutes. That makes the server create new land all the time, which is about the hardest a free server ever works. A small plugin wrote down how long each tick took.
Every run started from a fresh copy of the server. I ran the normal setup and each change three times in the same round, because the same setup can give very different results from one run to the next. This is a typical run of each. Drag the slider to choose what counts as slow.
Two minutes of ticks
Each bar is one tick of the test server, five players flying into new land
Over six runs of each, the normal setup had 407 ticks over 50 ms per run on average. With 10 ms windows it was 129, a bit more than 3 times fewer. While the players were flying, one tick in a hundred took 82 ms or more before, and 64 ms or more now.
Two things didn't change. All runs kept 20 ticks a second on average, because a server catches up after a slow tick. That's why TPS alone doesn't show this kind of lag. The single slowest tick of a run didn't get better either: it was between 102 and 212 ms before and between 111 and 221 ms now.
Everything else I tried
Before settling on this I tried most of the things people usually suggest for a faster server. This chart has one dot per run. It also shows how much a result can change between runs: the normal setup itself ranges from 39% to 189% of its own average. So a change only clearly did something when its runs land below most of that range. Five of the six runs with 10 ms windows were better than the best run of the normal setup, and the sixth was better than all but two of its fifteen.
Everything I tried
Slow ticks in each run, compared with the normal setup in the same round (100%)
Show the numbers
| Setting | Slow ticks per run | Middle run |
|---|---|---|
| Leaf instead of Paper | 657, 123, 154 | 24% |
| CPU windows of 10 ms | 147, 97, 128, 119, 190, 92 | 30% |
| CPU windows of 5 ms | 120, 116, 150 | 44% |
| CPU windows of 20 ms | 161, 139, 229 | 60% |
| Compact object headers | 139, 318, 730 | 67% |
| No compression to the proxy | 220, 339, 784 | 86% |
| The normal setup | 210, 733, 486, 316, 711, 152, 670, 612, 658, 140, 159, 512, 211, 512, 540 | 102% |
| The old memory setting | 795, 211, 499 | 105% |
| Tuned garbage collector flags | 138, 818, 546 | 115% |
| CPU burst | 517, 783, 191 | 132% |
| lz4 world files | 648, 719, 798 | 183% |
- Garbage collector flags, including the well-known Aikar flags that a lot of hosts advertise, made no difference next to Java's own defaults. ZGC and Shenandoah used about 2.7 GB at their peak in a 3 GB box, which is far too close to the limit.
- Windows of 20 ms and 5 ms both helped, but 10 ms helped the most.
- CPU burst lets a server save up CPU while it's quiet and spend it later. It didn't help here, because a busy server never has anything saved up. We still leave it on.
- Leaf did well in two of its three runs. It's already on the create page if you want to try it, but it changes some vanilla behaviour to be faster, so check that it suits your server first.
- lz4 world files and compact object headers made no clear difference.
The third change
Your server used to compress everything it sent to our proxy. The proxy then unpacked it and compressed it again for each player, so all of it was compressed twice. Now servers send it to the proxy uncompressed. That saves about 1% of a busy server's CPU, plus the proxy's work of unpacking it. It won't change lag, and you can see in the chart that it didn't. Servers in London keep compressing, because they're hosted on a home internet connection, and players who join through Helsinki reach them over it.
What you need to do
Nothing. Every change applies the next time your server starts, so if you've restarted it since 29 November, you already have them.
If your server still crashes, the console's "Why did my server stop?" card will try to tell you why. If it still lags, tell me on Discord: what kind of server it is, and when it happens.