If you're experiencing lag in your Minecraft server then this guide might help you reduce it or even completely remove it.
How to Optimize Your Server?
PAPERSPIGOT. Using PaperSpigot instead of Vanilla Minecraft. We recommend switching over to a PaperSpigot server due to the jar focusing on performance, stability and advanced features. For more information, read here.
STARTUP FLAGS. These flags are designed to improve the performance of your server through garbage collection, memory-, performance- and optimization management. There are also flags called "Aikar's Flags" which are a set of JVM flags designed to improve the performance of your Paper server.
Check out this article explaining how to toggle different flags on your server:
How to Change Server's Startup Parameters (Aikar's Flags)?
This article shows you step-by-step on how to enable/disable various startup parameters.
WORLD PRE-GENERATION. Since the Minecraft world is pretty much limitless, it's recommended to set up a world border and pre-generate your map. This prevents new chunks from being generated which really shows in performance.
Check out this article on how to pre-generate your world:
How To Pre-Generate Your World?
This article explains how to pre-generate your world using the Chunky plugin.
SERVER.PROPERTIES. It's recommended to change the view-distance and simulation-distance in your server.properties file if you're experiencing lag. You can try lowering it 2 at a time to see if reducing it works.
ADDITIONAL MODS. If you're running Fabric or Forge game version then you can also optimize your server by installing some performance mods:
FerriteCore (Fabric): https://www.curseforge.com/minecraft/mc-mods/ferritecore-fabric
FerriteCore (Forge): https://www.curseforge.com/minecraft/mc-mods/ferritecore
Lithium (Fabric & Forge): https://www.curseforge.com/minecraft/mc-mods/lithium
Krypton (Fabric): https://www.curseforge.com/minecraft/mc-mods/krypton
ModernFix (Fabric, Forge, NeoForge): https://www.curseforge.com/minecraft/mc-mods/modernfix
ADDITIONAL PLUGINS. You're not limited to only changing the base files of your server. You can install additional plugins to your server such as the following:
ClearLagg: https://www.spigotmc.org/resources/clearlagg.68271/
StackMob: https://www.spigotmc.org/resources/stackmob-enhance-your-servers-performance.29999/
DAILY SERVER RESTARTS. To prevent your server from getting overloaded from being online for long amounts of time by saving frequently visited world chunks and other such data to the server's Memory you should also set up automatic scheduled restarts.
Please check out this FAQ article for instructions on how to do that:
How To Set Up Automatic Schedules
This article will explain step-by-step on creating a schedule in the game panel.
For more information on how to optimize your server even more, check out this guide on SpigotMC: https://www.spigotmc.org/threads/guide-server-optimization%E2%9A%A1.283181/