The key to understanding what is causing lag is to understand how Minecraft works. Minecraft server software all operate in a similar matter with one key problem: there is no multi-threading or timing limits for the main game loop. When the server goes to tic, it runs through every TileEntity update, entity update, block update, events and other processes until it's done. This all occurs on one thread, and the next loop cannot start until the current one finishes. The world will not update, players will not appear to move and entities will be frozen in place. Ideally each tic should take no more than 50ms to maintain 20 Tics Per Second (TPS). This can go as low as 55.55ms for 18 TPS with minimal issues. Any lower than this and you will begin to see lag.
There are many things that can cause lag but a few of them will be the most likely culprit for most servers.
16*16*256
. This might not sound like a lot but when multiplied out that means there are 65,536 blocks per chunk. Each player can have more than 200 chunks loaded around them, depending on your configuration. Thats upwards of 13,107,200 blocks. This takes up a lot of memory. Also, if even 1% of those are TileEntities that's 131,072 TileEntities loaded that need to update every tic. Mods are notorious for having slow processing times on TileEntities.Finding the cause of lag is generally a simple procedure nowadays as most Minecraft server software is built with profiling tools included.
To get a detailed timings report you can use the follow command.
/timings on
You will want to wait a few minutes and let it lag while your timings are running. After a while, generate the report.
/timings paste
This will give you a link to a website with a nice breakdown of the report with easy options to sift through all the data you are getting. You can learn more on how to read these at Spigot's timing wiki.
You will want to turn timings off afterwards, as you do not want junk data clogging up your next reading, and timings adds additional time to the tic.
/timings off
To get a detailed timings report you can use the follow command.
/sponge timings on
You will want to wait a few minutes and let it lag while your timings are running. After a while, generate the report.
/sponge timings report
This will give you a link to a website with a nice breakdown of the report with easy options to sift through all the data you are getting. Since Sponge's timings system is based off of Spigot's you can learn more on how to read these at Spigot's timing wiki.
You will want to turn timings off afterwards, as you do not want junk data clogging up your next reading, and timings adds additional time to the tic.
/sponge timings off
You can also reset the timings.
/sponge timings reset
server.properties
A big portion of lag on modded servers comes from tile entities. These are the entities created for blocks that are used for processing the block's functionality and events. If these take too long or there are too many it can increase the time per tic bringing down the total server TPS. A way to visualize these problems is to use a mod called LagGoggles. You can download this mod from CurseForge.
See our tuning guide: How to Optimize Your Vultr Minecraft Server