What is Spark?

Spark is a profiler tool for your game and server. It can be used to track how long tasks take to complete in a single tick, how many entities there are in a world, and the overall health of the world. Whether the server has mods or plugins does not matter as Spark is available for modded servers such as Forge and Fabric as well as plugin servers such as Bukkit and Sponge. Those using Paper on versions 1.21 and above will find Spark already bundled into their server.

Installing Spark is just like any mod or plugin, First, download the mod or plugin from Curseforge or their website. Once downloaded, simply upload the file into the server’s mods or plugins folder and start the server. From there, Spark will be waiting in the background, ready to track performance on a server.

Why do I need Spark?

While it may not appear to do much, Spark is an incredibly handy tool in diagnosing server lag. We can use Spark to get an idea of how healthy the server is. As a diagnostic tool, it tracks down the source of lag based on how long a tick takes to perform.

Let’s say the server is slowing down. To start diagnosing the type of lag we are looking at, we can get a health report of the server. If we see that TPS is anywhere below 20, that means the server is experiencing a heavy load on performance. The lower the TPS, the more severe the lag is. From there, we can create a profile of the server, observing any drops in performance, the load on the server, and anything that is happening.

Spark alone will not solve the lag, but it does offer pathways to reduce it. Depending on what the source of the lag is, the solutions will involve reconfiguring automation and machinery, limiting the number of entities on the server, or increasing the amount of RAM if memory usage is high.

Taking a look at Spark

The first thing to do when we install Spark is to get to know what we are looking at. After all, you won’t know how to diagnose lag if you are not sure what you are looking at. For this example, I will be using Spark on a server running Minecraft 1.12.1

Create a Health Report

A Health Report is a general overview of what is happening on the server. This is good to get a quick idea of how the server is performing, such as memory usage, CPU usage, and TPS over time. Having a quick view of what is happening here can help identify if the lag is coming from the server itself, or if there’s something else at play.

A health report of the server as seen in-game. We can see the server’s TPS has been consistently at 20, CPU usage has been stable in the green area, and that memory usage is at a quarter of the allocated RAM. This report indicates the server is currently healthy.

To generate a health report, run /spark healthreport in-game or spark health in the server console. Having this quickly identifies how long the server lag has been going on for and how persistent it is. Signs of lag would be increasingly high CPU usage, decreasing TPS, or spikes in their values, indicating unstable performance.

Start the Profiler

If we need to take a deep dive into how the server is performing, we can start a profiler. This can be done by running /spark profiler start, where we will be told that Spark is now running a profile. Now, there are two things we can do here. One thing we can do is run the profile for about a minute before stopping it with /spark profiler stop, which will generate a profile. Alternatively, we can run /spark profiler open to get a live view of the server’s performance while it is running.

We can also start a profiler automatically when the server starts, allowing for a full view of the server’s performance. This is done by opening up the configuration file stored in config/spark/config.json. From there, set backgroundProfiler to true and we can get a profile started after a quick restart. All we have to do now is run /spark profiler open if we suspect there is server lag.

For our server, we are going to open the profile while it is running. This helps us get an idea of what the server is doing without needing to create a new profile each time. When we open the profiler, we will get a general overview of what resources the server is using and how much.

The default view of a Spark profile. From here, we can view a basic breakdown of various stats about the server. For us, the most important numbers to check are the TPS, MSPT, CPU, and Memory. Other statistics such as the GC (Garbage Collector) are handy, but not immediately important.

Let us start with this general overview and what matters most. First, we have the TPS, which stands for Ticks Per Second. A single second is equal to 20 ticks, and each tick lasts 50 milliseconds. We want a server to be running at 20 TPS and anywhere below 50 milliseconds in order to run smoothly. If the MSPT, or Milliseconds Per Tick, is too high, the TPS starts to drop.

Next is the CPU. The CPU is the brains of your server and is what processes information. For the most part, there is nothing to worry about the CPU as our machines have some of the latest hardware available. While high CPU usage can be symptomatic of server lag, it can also indicate that there is a lot of server activity and that the server is running fine.

Finally, there is the Memory. Unlike the Memory graph seen in the Command Center, this line shows how the game is actually using the memory, rather than how much memory the server has allocated itself. This will constantly be up and down depending on what the game is doing. This is a more accurate view of memory as it shows how the resources are handled by the game. Should this be consistently high, it means the server is struggling to allocate resources.

The view of the Server Thread. This view is looking at every thread, which includes the base game and mods. Label is set to time per tick, this way we can see how long a tick lasts. Currently, a single tick is lasting nearly 50ms, but we can also see 44ms is dedicated to waiting for the next tick, indicating that the logic has completed and is waiting for the next tick.

Let’s move on down to the bottom of the profile here labeled Server Thread. This is where we see every line of code being run on the server. Many different features of the game, such as entities and functional blocks like Furnaces, run logic every tick, so they will all show up here. So long as logic runs on every tick, we can see it show up here.

There are two ways to display a Server Thread time. One is a percentage, which shows what fraction of the time is being spent on each line of code. The other displays how many milliseconds it took for a line of code to run. When it comes to diagnosing lag, I recommend switching to millisecond time because it shows just how long a single tick lasts. The average server tick should last less than 50ms. Any higher, and TPS will start to drop from 20.

A view from the World tab. This shows a summary of how many entities there are on the server and in which world they are spawning in. Numbers like this are normal for a new server with just one player, but more can exist depending on how the server has been used. It is a good idea to look in here for server lag first because it quickly shows overcrowding.

One more important view is the World tab. Similar to how Observable works, Spark can also track how many entities there are in a world, from the total count to the distribution across each region. It is by no means a granular view of entities in the world, but it helps to identify if the distribution of entities is normal or if a mob farm is going crazy.

Entities are tallied based on what dimension they are in, how many there are in total, and their distribution by Region. For example, the overworld may have no mob farms running, but in the Nether, a Wither Skeleton farm is active.

How Spark can Diagnose Lag

So, with all this knowledge, how can Spark be used to diagnose lag? This all comes down to where the problems are happening and what can be done about it. To diagnose lag, there are a few steps to take.

Basic steps on how to diagnose server lag and possible solutions. For most sources of server lag, this chart helps to find out what is causing it.

First, we begin with a health report. Run the command /spark healthreport and we can get an overview of the server’s performance. Take a look at the TPS, then the CPU and Memory to see if the increased use of resources correlates with the TPS. If we see the CPU and Memory are high and TPS is low, then we need to get a profile started. Otherwise, if the health report shows no abnormal performance, this may be the result of Client-side Lag or Network Lag. To be absolutely sure, we can open a profile.

If a background profiler is not configured, run /spark profiler start and wait about a minute to populate the profiler with data. After that time, run /spark profiler open and then open the URL generated in a browser. From here, we will want to check a few things.

Once we have a profile running, we can choose to open, top, or cancel the profiler. In this case, we want to get a view of the server’s performance in action, so we run the command to open the profiler, then click on the link generated in chat.

Firstly, scroll down to the Server Thread and change the view to milliseconds. If we see this number is above 50ms, then we know that the server is under heavy load. The source of this will vary, so the next things we will want to check is the World tab and the Server Thread.

Starting off simply, we will look at the World tab for abnormal entity counts. Depending on how many players there are on the server, where the players are, and what is happening in the world, the entity count can vary from a couple dozen to around a hundred of a single entity. Abnormal counts may be several hundreds or thousands of a single type of mob.

Skeleton mob farms, or uncontrolled mob spawns? Numbers like this may not indicate server lag, but it can steadily lead into it if these numbers are allowed to grow. Some mobs can impact performance more than others, and Skeletons are one such example, so allowing them to spawn too much can slow down a server.

Should the numbers seem normal, we will check the Server Thread for any performance-impacting entities or block entities - blocks that process information, such as machines. Clicking on a single line will open up what other lines of code were running at that time. Spark sorts these by time, so we will want to click the first method of each stack until we get to an entity or a block, or any other feature that may show up. If we see that “timed wait” is at the top, then that means the server is idling until the next tick, which often happens when the server is not lagging.

If after checking all these we see all these numbers are normal, we will need to check the hardware for the server, such as the memory allocated. What should be noted is how much memory the server is using in a set period of time and what is happening on the server. If the Memory is consistently high but everything else appears normal, then it is possible that the server will need to allocate more memory.

What happens if everything on the Spark profile appears normal? There are two options here. First, giving the server a quick restart. Servers that have been online for long enough - especially modded servers - may begin experiencing lag from staying online too long, so a restart can help clear up old data in Memory. Otherwise, the lag may be Client-side Lag or Network Lag.

Conclusion

Spark is a sophisticated and powerful tool in providing a solution to resolving server lag. With a few simple tricks to knowing what features to use in Spark, it can be easy to find out what the problem is, and thus preventing further issues in the future. Of course, Spark is just a tool for identifying server lag, and the causes of lag are varied.

If you need help understanding a Spark profile, don’t hesitate to reach out to Support! You can get in contact by clicking on the red bubble icon in the bottom right of the website, or send us an email. Want to get started with your own server? Check out our affordable plans, and get started with your own Minecraft server in just a few clicks. Don’t forget to check out our Discord, where you can also meet up with other players and hosts for extra tips on managing your own server.