Minecraft – how to prevent lag in minecraft server

minecraft-java-editionminecraft-java-edition-serverminecraft-redstone

noob here… i started a server with some friends but idk how redstone function and how it can implicate on lagging the server, i builded a pumpkin and melon farm with observers and pistons and it's kinda ok but its the only farm so i'm scared of thinking the base area will handle being constantly loaded and BOOM server crashed no one can open it ever again…

the question: i'm confused about rendering and lagging, should i build farms far away from my base and spend some minutes afking in the chunk to farm? if yes, should i build them in different areas to prevent stacking too much in few chunks?
how many chunks far away from constantly loaded chunks??
and witch mechanics create lag? i know about to many hoppers and entities like minecarts are better to avoid

Best Answer

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.