# Lag and Profiling

## Lag <a href="#lag" id="lag"></a>

For identifying Lag sources/causes most of our packs have Spark and Observable in them by Default.

#### [Spark Profiler](https://spark.lucko.me/docs) <a href="#spark-profiler" id="spark-profiler"></a>

Normal players also have access to the command `/spark tps` & `/forge tps` and that gives a general indication of any potential lag issues that might need investigating.

**For Spark**, players in SP worlds with cheats enabled, or Server OPs can use the command `/spark profiler --timeout 180` to get a 3 minute snapshot of the server and anything that could be causing TPS issues. You can look at the URL returned by the mod to see an interactive online view of all server threads. Users can also use the command `/spark profiler --only-ticks-over 100 --timeout 60`, to identify intermittent lag spikes.

Note

For profiling client side FPS issues, use the `sparkc` command instead using same arguments above.

***

#### [Observable](https://legacy.curseforge.com/minecraft/mc-mods/observable) <a href="#observable" id="observable"></a>

Observable has the same permission requirements, but users need to set a keybind in their Keybinds settings to open the UI, from there click the profile TPS button and wait for it to complete, then depending on the mc version, you will either get a url, or an in-game table listing what blocks/entities are costing the most TPS, it will also visually highlight blocks with a spectrum color coding from **Green** to **Red**, with things colored in red generally being the worst for performance.

Observable is an in-game profiler that can be used by anyone (1.20+, enabled by default in ATM9 and *must create a keybind*). In order to use the “Visit” button on the web page, you *must be op*.

#### [Crash Utilities](https://legacy.curseforge.com/minecraft/mc-mods/crash-utilities) (Item Clear) <a href="#crash-utilities-item-clear" id="crash-utilities-item-clear"></a>

By default, **Crash Utilities** comes with most of our packs, though one feature **Item Clear** is disabled. It’s a very handy feature to have enabled with packs containing farms and automation to prevent massive entity leaks, which causes lag & crashes. This can keep your server entity count low for better performance.

To enable, locate and open `world/serverconfigs/crashutilities-server.toml`. Very top section, set `enabled` to `true`. The `timer` is the amount of time in **minutes** entities will be checked, followed by an Item Clear chat announcement when entities go over the `maximum` threshold.

When editing configs, please make sure server / client is not running

For clients, it’s safe to edit `world/serverconfigs/` while not in the world and or restarting entire client.

#### Useful Commands <a href="#useful-commands" id="useful-commands"></a>

<details>

<summary>General Commands</summary>

Kill Item Entities (Or Specific Entity)

```
/kill @e[type=minecraft:item]
```

Command may need to be executed more than once to clear all entities. Additionally, the **Crash Utilities** entities list command can be used to locate entities before they’re cleared.Kill Everything, Except Players

```
/kill @e[type=!minecraft:player]
```

</details>

<details>

<summary>Spark</summary>

Run Server Side Profiler (TPS Issues)

```
/spark profiler --timeout 30
```

Run Client Side Profiler (FPS/TPS Issues)

```
/sparkc profiler --timeout 30 
```

`--only-ticks-over 20` argument will record only ticks that’s over 20 that’s considered problematic.

`--thread *` can help record all threads Spark may not pick up.

</details>

<details>

<summary>Crash Utilities Commands</summary>

Entities List

```
/cu entities list
```

Item Clear (Must Be Enabled in config)

```
/cu callItemClear
```

Teleport Player To Spawn (Even Offline Player(s))

```
/cu unstuck <name>
```

Open Player Inventory (Even Offline Player(s))

```
/cu inventory <name>
```

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://allthemods.gitbook.io/guides/servers/lag-and-profiling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
