Skip to content

Published on · 4 min read

How to find what is lagging your Paper server with spark

A step-by-step guide to reading TPS and MSPT, profiling with spark and finding the plugin, entity or setting that is slowing down your Minecraft server.

  • Minecraft
  • Paper
  • Performance

When a Minecraft server starts lagging, the usual reaction is to remove plugins or lower the view distance until the problem goes away. Sometimes that works, but it almost always costs something players liked and never explains what was actually wrong. The faster path is to measure first. This post shows how I do that with spark, the most widely used profiler on Paper servers today.

TPS and MSPT: what to watch

The server runs the world in cycles called ticks. The target is 20 ticks per second (TPS), which gives a budget of 50 ms per tick. As long as each tick fits in those 50 ms, TPS stays at 20 and the game feels smooth. When a tick takes longer, the server falls behind and players notice blocks snapping back, mobs teleporting and slow commands.

That is why the most useful number is not TPS but MSPT (milliseconds per tick). A server at 20 TPS with an MSPT of 45 is already at the limit; at 15 MSPT it has plenty of headroom. Always check MSPT at peak times, when there are more players and more loaded chunks.

Installing and checking the basics

Recent Paper versions ship with spark built in. On older versions, install the spark plugin as usual. With it running, two commands give you the overview:

/spark tps
/spark health

The first shows TPS and MSPT over the last seconds and minutes. The second adds CPU, memory and garbage collector information. If memory is always close to the maximum and the GC runs constantly, the problem may be memory rather than processing.

Recording a profile

The profile is where the cause shows up. Start the profiler while the lag is happening, ideally with a full server:

/spark profiler start --timeout 300

After five minutes spark stops on its own and gives you a link to the web viewer. If the lag comes in spikes, record only the slow ticks:

/spark profiler start --only-ticks-over 60 --timeout 600

The report then ignores normal ticks and shows only what happened during ticks above 60 ms.

Reading the report

The viewer shows a call tree with the share of time spent at each point. In practice I look for three things:

  • A plugin name in the tree. If a plugin package takes a large slice of the tick, it is the first suspect. Expand it down to the method and check whether it is an event fired very often, such as player movement, or a scheduled task.
  • Entities and tile entities. A lot of time in tickEntities points to too many mobs, villagers or dropped items. Hoppers and redstone farms show up as tile entities.
  • Chunk loading and generation. Players exploring new terrain generate the world on the fly. Pre-generating the map solves much of this.

To confirm a suspicion about entities, Paper has a command that lists entities by type and chunk:

/paper entity list

A farm with hundreds of mobs in a single chunk usually shows up right at the top.

Fixing the cause, not the symptom

Once the bottleneck is known, the fix depends on what showed up:

  • Heavy plugin: update it, replace it or fix the code. In custom plugins, the most common wins come from moving database queries off the main thread, caching, and avoiding expensive work in frequent events.
  • Entities: per-chunk limits and farm rules in the Paper configuration, plus a conversation with players about farm sizes.
  • Chunks: pre-generate the world, tune view-distance and simulation-distance and set a world border.
  • Memory: review the allocation and JVM flags before simply adding more RAM.

After each change, record another profile under the same conditions and compare. If MSPT did not drop, that change was not the cause and can be reverted.

When one server is not enough

If the profile shows time spread evenly with no single culprit, the server may simply be doing too much. At that point it is worth splitting the game: the lobby on one server, each game mode on another, all behind a Velocity or BungeeCord proxy. Each server gets the full 50 ms again for a smaller group of players.

If you want help diagnosing or optimizing your server, see how I work on Minecraft plugins and servers.