how to prevent lag in minecraft server?
Solution 1:
Render lag, or low FPS is a client-side issue. Your server (if it's on a different machine) can run fine while your game; client is a PowerPoint.
Server lag in ideal conditions on the other hand, is caused by having too many ticking actions (ie. too many mobs, players moving/updating, redstone happening) and cannt process everything fast enough to maintain 20 TPS (ticks per second; times per second the game updates the world state/simulates at).
It is possible to also get performance drops in the client despite ideal network conditions if too many things update at once, needing the game to redraw and re-render more than your computer can handle.
As for what can cause this: everything. All entites and some blocks (ie. Redstone, Furnaces, etc.) tick. Some tricks you can employ to prevent this, though if your server is sufficiently powerful (not running on last gen), this should not be an issue. Tricks include:
- Clearing the world (to bedrock) around any highly complex (builds with redstone stretching at least the view limit) builds
- Avoid building entity or redstone heavy contraptions near spawn (spawn chunks are always kept loaded)
- Limit your build scope/size?
- Not doing server intensive tasks elsewhere (like flying tens of blocks per second at the same time as others).
- Have "lagging" builds at least two (server) render distances apart. The default is 10 chunks radius, so 320 blocks.
As always, you can always mitigate this by upgrading your computers/server.
Also, if your client and server are on the same machine, both will lag if one taxes your system to its full capacity.