[PR #874] [MERGED] Server ticks: HORIZON_SPIKES logs slow ticks with their CPU time and spans #2878

Closed
opened 2026-11-02 15:59:48 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/874
Author: @ludovic111
Created: 10/18/2026
Status: ✅ Merged
Merged: 10/18/2026
Merged by: @ludovic111

Base: main ← Head: perf/server-tick-spikes


📝 Commits (2)

  • be03fec Server ticks: HORIZON_SPIKES logs slow ticks with their CPU time and spans
  • fcf3a3e spans: test that the thread CPU clock counts work, not sleep

📊 Changes

6 files changed (+82 additions, -7 deletions)

View changed files

📝 Cargo.lock (+1 -0)
📝 crates/horizon-client/Cargo.toml (+4 -0)
📝 crates/horizon-client/src/game/dedicated.rs (+1 -1)
📝 crates/horizon-client/src/game/integrated.rs (+2 -2)
📝 crates/horizon-client/src/game/levels.rs (+32 -1)
📝 crates/horizon-client/src/spans.rs (+42 -3)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

What

With HORIZON_SPIKES=MS, a dedicated or integrated server tick longer than MS ms is now logged with three things:

  • the server thread's CPU time over the tick (CLOCK_THREAD_CPUTIME_ID, through rustix, which is already in the lock file);
  • the mob count;
  • the tick's spans, as the frame report shows them.
Horizon: slow tick 36.4 ms, cpu 35.9 ms (30 mobs): tick_lan 34.7, tick_mobs 1.0

A tick with much more wall time than CPU time waited, either for a lock or for a core on a busy machine. That is how to tell Horizon's own spikes from machine load.

There was also a leak: spans recorded on a server thread were never taken, so with HORIZON_SPIKES set they grew for as long as the server ran. Now they are taken every tick.

Why

Brief perf-ticks-9, task 3: measure tick_mobs and tick spikes on an idle machine. On the Mac mini, perf-ticks-8 saw the game thread off the CPU during the spikes.

What it measured (ThinkPad, idle: Kaby Lake-U, 4 threads)

tools/server_bench.py --servers horizon --bots 1 --behaviour walk,explore --explore-speed 10 --warmup 120 --seconds 240 --nice 19 with HORIZON_SPIKES=0, which logs every tick. Server and bot both ran on the ThinkPad. The first 200 ticks are skipped.

pass ticks wall avg / p50 / p95 / p99 / max CPU p99 / max wall − CPU p99 tick_mobs p99 / max mobs
walk 7,154 2.64 / 2.3 / 4.7 / 11.6 / 69.9 ms 10.6 / 62.4 ms 0.7 ms 2.3 / 7.2 ms 30
explore 7,153 6.00 / 3.8 / 18.3 / 26.4 / 79.8 ms 21.5 / 42.1 ms 12.9 ms 6.4 / 33.0 ms up to 94
  • Walking, the spikes are Horizon's own: CPU time is wall time. All of them are in tick_lan. A second run, with temporary spans inside it, put them in Hub::update_chunks, which encodes chunk packets on the server thread (ChunkEncoder::body_in): 25–35 ms per batch walking, up to 54 ms exploring. One 33 ms tick_sculk_blocks tick showed up too.
  • tick_mobs is not a spike source on an idle machine.
  • Exploring, the server thread is also off the CPU for up to 13 ms (p99). The ThinkPad's 2 workers, the bot and the server share 4 threads there.

The server's own /tick query agrees: walk MSPT 2.72, P95 4.67, P99 17.5; explore 6.29, 18.9, 31.6.

Checks

  • cargo fmt --all --check and cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test -p horizon-client --lib: 868 passed on be03fec7. The new thread_cpu_counts_work_not_sleep (unix) passes on its own.
  • Without HORIZON_SPIKES the tick runs tick_server exactly as before. CI parity covers --changed.

Needs Ludovic

Nothing.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/874 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/18/2026 **Status:** ✅ Merged **Merged:** 10/18/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/server-tick-spikes` --- ### 📝 Commits (2) - [`be03fec`](https://github.com/horizon-rust/horizon/commit/be03fec7fcaebafb811ee713a7073bb9f6730bd9) Server ticks: HORIZON_SPIKES logs slow ticks with their CPU time and spans - [`fcf3a3e`](https://github.com/horizon-rust/horizon/commit/fcf3a3e267bdc93d5637dac71b29b8459bca24b1) spans: test that the thread CPU clock counts work, not sleep ### 📊 Changes **6 files changed** (+82 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+1 -0) 📝 `crates/horizon-client/Cargo.toml` (+4 -0) 📝 `crates/horizon-client/src/game/dedicated.rs` (+1 -1) 📝 `crates/horizon-client/src/game/integrated.rs` (+2 -2) 📝 `crates/horizon-client/src/game/levels.rs` (+32 -1) 📝 `crates/horizon-client/src/spans.rs` (+42 -3) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What With `HORIZON_SPIKES=MS`, a dedicated or integrated server tick longer than MS ms is now logged with three things: - the server thread's CPU time over the tick (`CLOCK_THREAD_CPUTIME_ID`, through `rustix`, which is already in the lock file); - the mob count; - the tick's spans, as the frame report shows them. ``` Horizon: slow tick 36.4 ms, cpu 35.9 ms (30 mobs): tick_lan 34.7, tick_mobs 1.0 ``` A tick with much more wall time than CPU time waited, either for a lock or for a core on a busy machine. That is how to tell Horizon's own spikes from machine load. There was also a leak: spans recorded on a server thread were never taken, so with `HORIZON_SPIKES` set they grew for as long as the server ran. Now they are taken every tick. ## Why Brief perf-ticks-9, task 3: measure `tick_mobs` and tick spikes on an idle machine. On the Mac mini, perf-ticks-8 saw the game thread off the CPU during the spikes. ## What it measured (ThinkPad, idle: Kaby Lake-U, 4 threads) `tools/server_bench.py --servers horizon --bots 1 --behaviour walk,explore --explore-speed 10 --warmup 120 --seconds 240 --nice 19` with `HORIZON_SPIKES=0`, which logs every tick. Server and bot both ran on the ThinkPad. The first 200 ticks are skipped. | pass | ticks | wall avg / p50 / p95 / p99 / max | CPU p99 / max | wall − CPU p99 | `tick_mobs` p99 / max | mobs | |---|---|---|---|---|---|---| | walk | 7,154 | 2.64 / 2.3 / 4.7 / 11.6 / 69.9 ms | 10.6 / 62.4 ms | 0.7 ms | 2.3 / 7.2 ms | 30 | | explore | 7,153 | 6.00 / 3.8 / 18.3 / 26.4 / 79.8 ms | 21.5 / 42.1 ms | 12.9 ms | 6.4 / 33.0 ms | up to 94 | - Walking, the spikes are Horizon's own: CPU time is wall time. All of them are in `tick_lan`. A second run, with temporary spans inside it, put them in `Hub::update_chunks`, which encodes chunk packets on the server thread (`ChunkEncoder::body_in`): 25–35 ms per batch walking, up to 54 ms exploring. One 33 ms `tick_sculk_blocks` tick showed up too. - `tick_mobs` is not a spike source on an idle machine. - Exploring, the server thread is also off the CPU for up to 13 ms (p99). The ThinkPad's 2 workers, the bot and the server share 4 threads there. The server's own `/tick query` agrees: walk MSPT 2.72, P95 4.67, P99 17.5; explore 6.29, 18.9, 31.6. ## Checks - `cargo fmt --all --check` and `cargo clippy --workspace --all-targets -- -D warnings`: clean. - `cargo test -p horizon-client --lib`: 868 passed on be03fec7. The new `thread_cpu_counts_work_not_sleep` (unix) passes on its own. - Without `HORIZON_SPIKES` the tick runs `tick_server` exactly as before. CI parity covers `--changed`. ## Needs Ludovic Nothing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:59:48 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2878
No description provided.