Repository navigation
Make Profile Events ±30x faster by using Per CPU atomics for server-wide and users - #105056
Conversation
|
Workflow [PR], commit [ed38f7a] Summary: ❌
AI ReviewSummaryThis PR rewrites PR Metadata
Findings
Final VerdictRequest changes. The counter-accounting fixes look much healthier now, but the current head still has an unproven async-signal-safe path, unresolved representative performance regressions, and two operational tradeoffs around retained per-user memory and host-CPU sizing that remain real in the current code. |
a19545c to
4851462
Compare
|
This was fixed by #105146. Let's update the branch. |
fd426da to
14ace03
Compare
|
Switching user counters as well, significantly improves the throughput, almost 30x Before using shared counter for users as well After |
08b149a to
afd8d1b
Compare
|
As @vadimskipin pointed librseq does not gives a lot of benefits here (16% difference between librseq and just per-cpu atomic in peak, while the difference between one atomic vs per-cpu atomic is 30x), removed - 16ae75e |
`test_hedged_requests/test.py::test_stuck_replica` is chronically flaky
on heavily overcommitted ASan/UBSan integration shards. The failure shape
in CIDB is identical across 9 unrelated PRs in the past 30 days:
pause_container('node_1') did not become observably effective within
90.0s ... still succeed after ~890 probe iterations; last outcome:
server replied (4 bytes)
The probe in `_wait_for_pause_effective` keeps receiving live ClickHouse
exception packets from `node_1` for the entire 90s budget, which proves
that `docker compose pause` returned success while the cgroup freezer
never actually froze the user-space tasks. The existing SIGSTOP fallback
in `ClickHouseCluster.pause_container` only fires when `docker compose
pause` raises an exception, not when it lies about success, so the
escalation path was never taken.
Switch this test to `cluster.pause_container_using_signal`, which uses
`SIGSTOP`/`SIGCONT` from the start. A signal cannot be silently lost the
way the cgroup freezer can, so the pause becomes observable on the very
first probe iteration. Same helper is already used by
`test_postgresql_replica_database_engine` for the same reason.
The change is local to one call site. The chronic flake hit
`Integration tests (amd_asan_ubsan, db disk, old analyzer, 1/6)` in the
following PRs (CIDB, last 30 days): ClickHouse#103404, ClickHouse#106311, ClickHouse#105010, ClickHouse#105056,
ClickHouse#104830, ClickHouse#106025, ClickHouse#100391, ClickHouse#106571, ClickHouse#103229. All show the same
`server replied (4 bytes)` outcome, distinguishing this from generic
flakiness.
Related: ClickHouse#106571
b42ac74 to
fb57ea0
Compare
fb57ea0 to
ed38f7a
Compare
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 220/237 (92.83%) · Uncovered code |
2bf720f
…er-cpu Make Profile Events ±30x faster by using Per CPU atomics for server-wide and users
`Regexps::LocalCacheTable::getOrSet` incremented `RegexpLocalCacheHit` or `RegexpLocalCacheMiss` on every lookup, and `MatchImpl::matchOneRow` does one lookup per row whenever the pattern of `LIKE`/`match` is not a constant. `ProfileEvents::increment` does an atomic add at every level of the counter chain. The user and global levels are per-CPU since ClickHouse#105056, but the thread group level is a single row, so every thread of the query wrote the same cache line on every row. The query was bound by that line: `re2_regex_caching` `#3` took 91 ms at both 8 and 32 threads, and its cost differed between server processes, which made `#3`, `#5` and `#6` of that test noisy on the amd performance shards. The table now counts hits and misses in two members and adds them to ProfileEvents once, in its destructor. A table is a local of `vectorVector`/`vectorFixedVector`/`constantVector`, so it lives for one block on one thread: the totals per query are unchanged (a miss is still counted before `createRegexp`, so a failed compile still reports it), and the shared counter is written twice per block instead of once per row. Tables that did no lookup report nothing, as before. With `trace_profile_events = 1` these two events now give one `trace_log` row per block (with the block total) instead of one per row. Release build, 8 threads pinned to 8 physical cores, 10 server processes per binary: `#3` and `#5` 90 -> 18 ms, `#6` 94 -> 34 ms, the other queries of the test unchanged; user CPU at 8 threads over 1 thread for `#3` goes from 5.2 to 1.0. At 32 threads `#3` goes from 91 to 15 ms. The new test checks the exact hit and miss totals for the three callers (String, FixedString and constant haystacks). Related: ClickHouse#121795, ClickHouse#100759 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Make Profile Events ±30x faster by using Per CPU atomics for server-wide and users. Guarded with "user_profile_events_per_cpu" server setting (uses ±640KiB per user on 64 cores, so in case of lots of users it may make sense to keep it disabled)
Benchmark
Version info
26.7.1.470(included in26.7and later)