How to fix Minecraft server lag
Server lag is not one problem. It is at least three, and they need different fixes. This guide helps you work out which one you have before you change anything.
First, which kind of lag is it?
- Server lag (low TPS). Blocks break late, mobs stutter, and rubber-banding hits everyone. The server cannot finish a tick in the 50 milliseconds it has. A healthy server runs at 20 TPS.
- Network lag (high ping). Everything is smooth but delayed. This is the distance between the player and the server, or a bad connection. No server setting fixes it.
- Client lag (low FPS). One player's game is slow. That is their computer, not your server.
Check with /tps on Paper, or /spark tps. If TPS is 20 and players still complain, it is probably network or client lag.
Step 1: lower the distances
Open server.properties and change these two settings:
view-distance=8
simulation-distance=6
view-distance is how many chunks around a player are sent to them. simulation-distance is how far from a player the server actually runs mobs, crops and redstone. Most servers feel the same at 6 to 8, and use much less CPU.
Step 2: pre-generate the world
Generating new terrain is the hardest job a server has. If players spread out into unexplored land, the server stalls while it creates chunks. Pre-generate the area around spawn while nobody is online, with a plugin such as Chunky:
/chunky radius 5000
/chunky start
It runs in the background. Do it before opening the server to a crowd.
Step 3: find the real cause with spark
Guessing wastes time. The spark plugin shows where the server spends its ticks.
/spark profiler start
Play for a few minutes during the lag, then:
/spark profiler stop
You get a link to a report. Look for plugins or tasks that take most of the time. Common culprits are a plugin doing slow work on the main thread, a huge number of entities in one place, or hoppers.
Step 4: tame entities
Mobs, dropped items and villagers cost much more than blocks.
- Limit animals per chunk, and clear dropped items from time to time.
- Do not stack hundreds of villagers or animals in one pen.
- In Paper's configuration (
config/paper-world-defaults.yml) you can lower how far mobs are active and how often they are ticked. - Large mob farms and hopper chains are the usual reason a healthy server drops to 15 TPS.
Step 5: check your plugins
Remove plugins one at a time and watch whether TPS improves. Keep only what you use. Old plugins that have not been updated for your Minecraft version are a common cause of trouble.
Step 6: only then, add memory
If the server runs out of memory, adding more helps. If it is short of CPU, memory will not help at all. The guide to how much RAM a server needs explains how to tell.
A quick checklist
/tpsshows below 20 during lag?view-distance8 andsimulation-distance6?- World pre-generated?
- spark report read, and the top item dealt with?
- Entities under control?
- Unused plugins removed?
If you work through those, most lag problems are gone before you spend a cent.