Diagnosing lag with the spark profiler
Paper already bundles spark. Start a profile, read the call tree, and find the plugin or mechanic eating your tick time, with a worked example.
Quick answer Paper 1.21 and newer already include spark, so there is nothing to install [3]. While the lag is happening, run
/spark profiler start --timeout 120. When it finishes it hands you a link to a call tree. Open the “Server thread”, follow the biggest percentage down level by level, and stop at the first method that belongs to a plugin or mod and owns a large share of the time. That is the thing to fix, remove or report.
Getting spark
On Paper 1.21 or newer, /spark already works. Paper bundles it and calls it the preferred way to profile [3]. If you want a newer spark than the bundled one, drop the standalone jar in plugins and add -Dpaper.preferSparkPlugin=true to the startup arguments [3][4].
Everywhere else you download the jar from spark’s downloads page and put it in mods or plugins, then restart [4]. The page lists builds for Bukkit/Paper/Spigot, BungeeCord, Velocity, Fabric, NeoForge, Forge, Sponge and a standalone agent [8]. For proxies the command changes: /sparkb on BungeeCord and /sparkv on Velocity [1].
You may have to give yourself the spark permission, or be a server operator [4]. If you have no in-game operator to hand, /spark health show is documented as printing its report to the console, which is a quick way to confirm spark is loaded [1].
Run a profile that catches the lag
/spark profiler start --timeout 120
--timeout stops the profiler on its own after that many seconds, so you cannot forget it running [1]. Paper’s docs use 600 seconds in their example and tell you to hand the resulting link to a plugin developer or the Paper support chat [3]. I would pick 120 and spend it on the lag itself. Paper’s docs say that for profiling to be effective the issue must be actively occurring [3], and spark’s README says around 30 seconds is enough to produce useful results [2].
Related commands [1]:
/spark profiler infoshows the profiler’s status./spark profiler stopends it early and shows the results./spark profiler openopens the viewer without stopping it./spark profiler cancelstops it and throws the data away.
The result is a link. spark uploads the profile to its viewer, and the docs say you can share the link with someone helping you or a plugin developer [5].
Read a report in four moves
The report is a tree of method names with percentages. Everything below is how spark’s viewer guide says to read it [5][6]. The tree below is a constructed example, not a real server’s report: I made up the plugin name, the method names and every percentage to show the reading steps. Your names and numbers will differ:
(constructed example, invented numbers)
Server thread 100%
Thread.run() 100%
MinecraftServer.run() 100%
(sleeping, waiting for next tick) 12%
MinecraftServer.tick() 88%
WorldServer.tickEntities() 21%
WorldServer.doTick() 17%
CraftScheduler.mainThreadHeartbeat() 41%
ExamplePlugin$SaveTask.run() 38%
ExamplePlugin.recalculateAllPlayers() 37%
(everything else) 9%
1. Open the Server thread. The viewer lists the profiled threads first. For a Minecraft server, the Server thread is the main game thread and the one you care about [5].
2. Check the sleep share. Sleeping is healthy: the server finished the tick early and waited for the next 50 ms slot [6]. In the example the server sleeps only 12% of the time. spark’s guide says that under 20% sleep the server is working pretty hard and may lag on some ticks, and under 5% it is probably lagging with no spare capacity [6]. If the server is holding 20 TPS, 88% of a 50 ms slot is an average tick of about 44 ms, so there is little room left for a spike. Remember spark’s caveat that these are averages [6].
3. Follow the biggest number. Ignore the entry-point frames (Thread.run(), MinecraftServer.run()) and look at what MinecraftServer.tick() splits into. The viewer guide’s rule is to follow the percentages next to each node [5]. Here CraftScheduler.mainThreadHeartbeat() is 41%, and the viewer guide identifies that frame as CraftBukkit running plugin scheduler tasks [5]. Entity ticking at 21% and the world tick at 17% are real work too, but they are the game doing its job.
4. Stop where the name stops being the game’s. Expand the scheduler frame. One plugin task, ExamplePlugin$SaveTask, owns 38% of the server thread, which is about 19 ms of every 50 ms tick slot if the server is holding 20 TPS (arithmetic on the example). Nothing else in the tree comes close. That is the finding.
My rule of thumb, not spark’s: if one plugin or mod owns around 30% of the server thread and the next owns under 3%, start there. A plugin that shows up at 1% is not a suspect. Almost everything appears somewhere.
If the names are meaningless obfuscated fragments, the viewer applies deobfuscation mappings automatically and has a dropdown in the top right if it guesses wrong [5].
Three viewer features that save time
- Sources view. It builds a separate tree for each plugin or mod, which is the fastest way to see who owns what when you suspect an add-on [5].
- Flat view with Bottom Up and Self Time. It lists the 250 slowest method calls at the top level. Sorting by self time ranks methods by the time spent in their own code, not in what they call [5].
- Bookmarks. Alt-click a method call to bookmark it. The bookmark is encoded in the URL, so the link you send keeps it highlighted and expanded for the person you share it with [5].
Lag that comes in spikes
A normal profile averages everything, so a 300 ms tick once a minute disappears into thousands of fine ones. spark’s guide has a two-step fix [7]:
- Run
/spark tickmonitor. It reports ticks that took at least twice the average by default, and--threshold-tick 50reports any tick over 50 ms instead, so you can line the messages up with what players were doing [1][7]. - Run
/spark profiler start --only-ticks-over 150so the profile contains only samples from ticks longer than 150 ms [1][7]. The guide suggests a threshold between 50 and 100 that is below the duration of the bad ticks. Its own example used 150 because the spikes it found lasted over 300 ms [7].
The TPS and MSPT post explains why the average hides these and what /spark tps shows for them.
Other flags worth knowing
| Flag or command | What it is for |
|---|---|
--thread * |
Track all threads, not only the server thread [1] |
--alloc |
Profile memory allocations (memory pressure) instead of CPU [1] |
stop --comment <text> |
Add a note that shows in the viewer [1] |
stop --save-to-file |
Save the report under the config directory instead of uploading [1] |
/spark health show |
Print a health report to the console, with TPS, CPU, memory and disk [1] |
/spark gcmonitor |
Report garbage collection activity, useful when hangs line up with GC [1][2] |
/spark health on its own opens a live dashboard that updates every 10 seconds [1].
Before you share a report
An upload is not private. spark’s policy says uploads are not listed or indexed, but anyone with the link can view and download them, and some fields can carry free text or configuration, such as JVM arguments, plugin descriptions and server configuration values [9]. spark strips known-sensitive settings such as the server IP and RCON settings before upload, but the policy says that filter only covers known settings [9]. At the time of writing the policy gives a 90 day retention for profiles [9]. Read the page before posting a link in a public Discord channel, and use --save-to-file if you would rather keep it local [1].
When the tree points at the game itself
Sometimes no plugin stands out and the weight is in tickEntities, the world tick or chunk loading. Then the fix is less work per tick, not a different plugin. Simulation distance is the first setting to look at, and the TPS post lists hoppers, redstone and mob counts as the other usual sources. I did not measure how much any of these costs in a real report, so profile your own server before you change several things at once.
Questions people ask
Do I need to install spark on Paper?
No. Paper 1.21 and newer bundle spark. To use a newer standalone spark jar instead, put it in the plugins folder and start the server with -Dpaper.preferSparkPlugin=true [3][4].
How long should I run a profile?
The spark README says about 30 seconds is enough for useful results [2]. Paper's example uses 10 minutes [3]. Either way, the lag has to be happening while the profiler runs, so start it when it is [3].
Who can see my profiler link?
Anyone who has it. spark's privacy policy says uploads are not listed or indexed, but anyone with the link can view and download the content, and uploads are deleted after 90 days at the time of writing [9]. Add --save-to-file to /spark profiler stop to keep the report local [1].
Does spark work on Fabric or Forge?
Yes. The downloads page lists builds for Bukkit/Paper/Spigot, BungeeCord, Velocity, Fabric, NeoForge, Forge, Sponge and a standalone agent [8].