Mineshire
All posts

Performance

Why your Minecraft server lags, and how to fix it

· 3 min read

“The server is lagging” can mean three separate things, and the fix for one does nothing for the others. Before you change any settings, work out which kind of lag you’re looking at.

Three kinds of lag

  • Server lag: the server can’t finish its work in time. Blocks you break reappear, mobs stutter, and everyone feels it at once.
  • Network lag: the connection between a player and the server is slow. Only that player has trouble, and the ping number in the player list is high.
  • Client lag: the player’s own computer can’t draw the game fast enough. The frame rate drops, but the server is fine.

If everyone on the server has the problem at the same moment, it’s the server. If it’s one player, look at their connection or their computer first.

What server lag means

The server runs the game in ticks, twenty every second, so each tick has 50 milliseconds to do all its work. When a tick takes longer than that, the game falls behind. You’ll see this as TPS, ticks per second, dropping under 20. The console may print “Can’t keep up! Is the server overloaded?”

On Paper and similar software you can type /tps to see the current number. A steady 20 is healthy. Below about 18 players start to notice.

The usual causes, in the order to check them

View and simulation distance. This is the most common cause on small servers, and the cheapest to fix. Each player makes the server load and process a square of chunks around them. Lowering simulation-distance from 10 to 6, or view-distance a notch or two, cuts the work a lot.

Too many entities. Large farms, hundreds of animals penned in one spot, item frames by the thousand, and hoppers that never stop moving all take time every tick. A single big mob farm can cost more than ten players.

Too little memory, or a badly chosen amount. Check the memory graph before assuming it’s something else. Repeated short freezes often mean memory pressure.

Chunk generation. Send three players flying off in different directions and the server has to invent a lot of brand new terrain, which is costly. Pre-generating the land around spawn while it’s quiet takes that hit away.

Plugins or mods. One badly written add-on can use more time than the entire rest of the game. Remove things you don’t need, and test by disabling suspects one at a time.

The hardware itself. One processor core does most of the work, so clock speed matters. A game or a video export fighting for that core shows up as lag as well.

Measure before you guess

Spark is a free profiler plugin that works with Paper, Fabric and Forge servers. Run its profiler for a few minutes while the server feels slow and it shows exactly where the time goes: which plugin, which mod, which kind of entity. That turns “I think it’s the farm” into a fact.

It takes a few minutes to set up and it’s the most useful tool a server owner can have.

What to try first

Lower simulation-distance by a few points. Restart. If that fixed it, you’re done. If not, look at who’s online and where, then check memory, then profile.

It also helps to stay realistic. A home PC that you’re also gaming on will always lag more than a machine that does nothing else. If you reach the point where the server and the game are fighting over the same processor, the honest fix is a separate computer, or waiting to play until the server is quiet.

Quick answers

Will more RAM fix lag? Only if memory was the cause. Look at the memory graph first, because lag from entities, chunks or a slow processor won’t care how much memory you gave it.

Does lag get worse with more players? Yes. Each player adds loaded chunks and entities, and the server does that work every tick.