No tutorials found
Last modified on Apr 21, 2020 in General
One of the biggest concerns for server owners is lag. Lag can be caused from a variety of ways, whether it’s from resources you add to your server or the hardware your server runs on, however, if you host with Apex, hardware shouldn’t be an issue. There are many ways that you can reduce lag. You can get plugins that can help reduce lag, you can upgrade your server ram, switch your jar to a more optimized version of Minecraft, optimize your files, and much more. With all of these solutions, you may be wondering what causes lag. There are different types of lag that can occur such as TPS, Latency, and FPS lag. We are going to break down all of the different types of lag and the best way to optimize your Minecraft Server.
Server Lag (TPS)
Server lag is represented by its TPS (Ticks Per Second). A servers TPS or Ticks Per Second is used to quantify the overall health of your server’s performance. Like a heartbeat, your server beats at a fixed rate of 20 ticks per second, so one tick every 0.05 seconds. On each tick, various aspects of the server advance a little bit; moving of mobs, the growth of grass, moving objects change position, mobs check their surroundings and update their behavior, health and hunger, and much more. The whole of your server revolves around the beat of your servers TPS. When at peak performance, 20 TPS, you’ll receive nominal gameplay without any server-side lag. But if your servers TPS drops, even a few ticks, you’ll begin to notice lag on the server.
TPS on the server is determined primarily by the speed and capabilities of the hardware used to host it. While the server’s hardware does play an important role in the server TPS, it is not the absolute determinate. Simply throwing the best hardware on a server will not guarantee its performance. What occurs on the server plays an equal role in determining the server’s TPS. Mismanagement of one’s server can be just as detrimental as adequate hardware.
When adding mods or plugins, you should be thinking about the long-term effects of your choices. Many new server owners will mistakenly assume that the number of people on their server will determine the performance of the server. The number of players on the server plays little part in the server’s overall performance. The primary cause of TPS drops is a result of what you have going on in your world. For modded servers this more apparent with all the new blocks and the functionality they provide.
For each modded block you add that provides some type of function, the server has to allocate resources to ensure that function is carried out. Now on its own that one block is of little consequence. But if that block forms an array as is typically done with solar panels, then the server will need to dedicate more resources to carry out that arrays functions. When we break it down we can get an idea of how much is really going on in the background.
If you have an array of 1000 solar panels, each panel when placed is constantly checking the time of day. It then checks the immediate surrounding blocks for cables to deliver power to. If one cable combines with another array, then that mainline is updated with the sum power of both arrays. These updates are happening every 0.05 seconds and when combined with everything else, it all adds up. It’s no surprise the strain it can put on a server that Minecraft wasn’t designed to run.
Client Lag (FPS)
Having low FPS will generally come with your game behaving slowly. If your frame rate is low enough, playing the game may feel like watching a slideshow as only a few different frames appear on your screen per second. It will make the game feel laggy, which is the last thing we want. Having a low frame rate on your server does not mean that the server is lagging but that your computer is failing to keep up with the game. If you do have a consistent low frame rate on your PC, you will most likely need to upgrade the graphics card, RAM, or the CPU.
It is very important that you know that there is a difference between server lag and low FPS. There are times that low FPS and server lag can appear at the same time, you may think that the FPS is due to the server having lag, but it is a separate issue. The lag is from server-side basically saying that it is having trouble keeping up with what’s going on in-game. If you have low FPS, it’s only because your computer hardware isn’t fit to run what’s happening in-game, even if the server didn’t have lag, your client would still have the low FPS. For example, if you’re playing a server with hundreds of other players running around on your screen, you may experience both low FPS and lag. The lag occurs because the server is struggling to keep up and slowing down with so much happening in one place at once, while the low FPS is a result of your computer struggling to display all those characters on your screen at once.
Replacing or upgrading hardware is not the only way to fix having low FPS though. In Minecraft, you can go to the video settings and reduce all of the functions. For example, you can turn clouds off so that your computer doesn’t have to try and load them in. It’s a good idea to close other processes that you don’t need. This frees up resources that your computer can dedicate to the game. You can do this quickly by closing anything that’s open on your Taskbar. It’s worth checking the task manager for background processes, too.
Another thing you can do is switch to the high-performance plan in your Windows power options. To do this, navigate to Settings > System > Power and click “Additional power settings” on the right side. This will lead you to the Power Options section of the Control Panel. Choose “Show additional plans” if necessary, then select the “High performance” option.
Connection Lag (Ping)
Connection lag correlates directly with ping. Ping refers to the network latency between client-side, and your Minecraft server. This reflects how long in milliseconds data takes to process and travel. Having a low ping is best as lower latency provides smoother gameplay. Typically, the further away a server is from your physical location, the greater your latency will be. The best way to minimize latency is by finding a server location near you. We have multiple different locations at Apex including Oregon, Nevada, Texas, Virginia, Quebec, United Kingdom, France, Singapore, Poland, Australia, Florida, Brazil, and China. Every one of these locations can be tested for ping so you can decide which location is best for your Minecraft server.
High latency/ping can cause lag. If you have high ping, it’s possible that you may time out of the server as they will often disconnect a client if the ping is too high. Similarly, client software will often mandate disconnection if the ping is too high. Having a high ping is not something that’s due to lag, but it causes lag. It may also crash the server because of the instability.
Some factors that might affect ping include Internet connection speed, the quality of a user’s Internet service provider, issues with the Minecraft servers network, and the configuration of firewalls. One of the most important factors in ping/latency is the location. For example, if you are located in the United States but are connecting to a server that’s located in Germany, the ping is going to be high for you in comparison to someone in Germany playing on the server.
Latency can change depending on network conditions and the status of the server to which you’re connecting. You can test how bad latency will be on a server by “pinging” the server. This determines how long it takes for the server to receive a message and respond. You can test ping two ways, the first is through the Minecraft client itself by simply hovering your mouse above your servers green connection bar to the right. This will display a number followed by “ms”, that number is your ping. The second is by opening the command prompt and typing “ping ServerIP” so for example “ping play.apexmc.co”, it may take a second to complete its test but you should see the average ping displayed.
Trying to find where lag originates is not always an easy task. On client side, you can see if you have lag by checking your FPS. You can check your FPS by pressing f3 in-game on Minecraft, this will open up a little console with all of your game details. If you have a very low FPS, then you are experiencing a client-side lag.
Connection lag can be tested by checking your pingto the server. Having a high ping will mean that you are experiencing delays with the connection.
Neither of these types is related to the server performance itself though. You can check your server performance by checking the TPS. If the TPS is low, you know that something is causing your server to run behind. Detecting what exactly the reason is can be a little bit troublesome, however, if you are running Paper and Spigot, you can run a timings report to break it down for you.
Timings allow you to monitor how long it takes the plugins installed on your server to process an event. This allows you to see where lag issues arise, as a misbehaving plugin may be causing a delay in the tick loop, causing the server TPS to go below 20. To run a timings report, type “/timings on” and after about 20+ minutes, type “/timings paste”. This will provide you a link, go ahead and click that and wait for the web page to load. The timings report is separated into sections for each plugin. The first two sections are Minecraft’s own tick events such as loading entities, chunks, etc. The rest is divided by plugin.
Reading a Timings Report
If you look to the top of the timings report, you are going to see a few general data points:
Total: The total time spent handling events Sample Time: Time the server has been collecting timings data for the report. Average Entities: The average number of activated entities, followed by the average number of total entities. Average Players: The average amount of players logged in during the sample time. Average TPS: The average server TPS during the sample time. In the headers of sections for plugins, there are two data points following the name and version: Total: The total time spent by the plugin processing events during the sample time. Pct: The percentage of the sample time this represents. Each section has several columns of data per event a plugin handles: Pct Total: The percentage of the total sample time spent processing the event. Pct Tick: The percentage of a single tick (50 ms) spent processing the event. Total: The total time spent during the sample time. Avg: The average amount of time spent per tick. Count: The number of times the event was fired and handled by the plugin. Vio: The percentage of the total violation count this plugin was responsible for. The violation count is the number of times a timer has caused TPS loss. Event: The name of the event.
Looking through the timings will help break down where lag is originating from. If you can see that a single plugin is taking a lot of time to process an event, it’s likely that the plugin is causing your server lag.
The Pct Total column is a good indicator of the overall TPS. If there are events that take up a large amount of time to process, it could mean that it is responsible for a TPS drop as a good amount of the game loop is spent on the event. Seeing a large number in the Pct Tick column and a low number in the Count column could indicate that a plugin is spending a lot of a single tick processing the event, and thus causing a lag spike. Coupled with a high violations count, this would mean that the plugin is an almost definitive cause of steady, repeated lag spikes.
Knowing how to optimize your server is vital in preventing server lag. This will be breaking down what you need to change in your server configuration to get the best possible performance without having to compromise your gameplay. We will be going through all of the steps in server optimization.
One of the most vital steps in lag removal is pregenerating the world. This should be done before anything else. The best way to do this is with the WorldBorder plugin. All you have to do is type “/wb set ” followed by “/wb fill”. This will start generating the world for you, make sure to set the radius to something reasonable like 5000 as pregeneration takes a long time.
One option that is beneficial to reduce on any type of Minecraft server is the view distance from the server.properties file. Any number between 4-8 should help with optimizing the server.
If you are running Craftbukkit or Vanilla, you will want to switch to Paper or Spigot. Both of these versions have optimizations for in-game ticks, chunk loading, block decay, and more optimizations for great performance. While both of these versions are great, Paper is recommended as it does not include async chunk loading which improves the server performance immensely.
Some of the main files that you will want to modify to really optimize your server is the Bukkit.yml, Paper.yml, and Spigot.yml. Below we have included areas of the configuration that you will want to change and what you will want to change it to. Keep in mind when going through this, that it does not need to follow this exactly, these are highly optimized to provide your server with the highest performance possible.
Make sure that you turn your server off completely before changing or modifying any of the configuration files. Each of these files can be found in the main directory of the FTP File Access.
spawn-limits: monsters: 50 animals: 8 water-animals: 3 ambient: 1 chunk-gc: period-in-ticks: 400 ticks-per: animal-spawns: 400 monster-spawns: 4
max-auto-save-chunks-per-tick: 6 optimize-explosions: false mob-spawner-tick-rate: 2 disable-chest-cat-detection: true container-update-tick-rate: 3 max-entity-collisions: 2 grass-spread-tick-rate: 4 despawn-ranges: soft: 28 hard: 96 hopper: cooldown-when-full: true disable-move-event: true non-player-arrow-despawn-rate: 60 creative-arrow-despawn-rate: 60 prevent-moving-into-unloaded-chunks: true use-faster-eigencraft-redstone: true armor-stands-tick: false per-player-mob-spawns: true alt-item-despawn-rate: enabled: true anti-xray: enabled: true
save-user-cache-on-stop-only: true max-tick-time: tile: 1000 entity: 1000 mob-spawn-range: 6 entity-activation-range: animals: 16 monsters: 24 raiders: 48 misc: 8 merge-radius: exp: 4.0 item: 6.0 nerf-spawner-mobs: true
Changing the base server files is not the only way to reduce or get rid of lag. There are many plugins out there that their sole purpose is for lag reduction. If you know which ones to use, you can find that lag can be reduced significantly on your server simply by installing a plugin or two.
These plugins aren’t guaranteed to completely stop the lag on your server, your server can experience lag for many different reasons, but they are known to help with optimization and should definitely reduce lag. If you do not know how to install a plugin onto your Minecraft server, you can follow our guide here.
Unfortunately with Forge, there are not any good optimization changes to the configuration files you can make. The main thing you can do to optimize your Forge server is by reducing the view distance from the server.properties file. Another way is with the use of mods, there are some mods out there that can help reduce server lag.
As with plugins, adding these mods is not going to guarantee that your server will no longer lag. However, this should help in the reduction of lag on the server and should help overall. If you do not know how to add individual mods to your server, you can check out our guide here.
One of the most important things that you can do as a server owner is making sure that your server is optimized and lag-free. When players join a server, they don’t expect to have issues with lag. In optimizing a server, it is important that you note the different types of lag and what you can and cannot control. You may not be able to control the lag they experience client-side, but you can surely do everything on your end to optimize the server.
If you are running a Vanilla Minecraft server, you may think that it won’t experience lag, I mean it is the base version of Minecraft with no optimizations. Unfortunately, though, this is not true. The newer updates such as 1.14 are known to have issues when it comes to lag. One of the best things you can do to reduce this lag is by switching from Vanilla Minecraft to Paper.
If you are running a modded Minecraft server, Forge, there are not a lot of optimizable configuration options, unfortunately. The best thing you can do for Forge is to pregenerate the worlds in single player with the mods and reduce the view distance from the server.properties.
With so many different versions of Minecraft and different types of lag you can experience, as a server owner you can only control the server-side lag. If you follow everything from this guide, it should increase the performance of your server exponentially.