Repository navigation
Show throttler wait time in the client progress bar - #118536
Conversation
Rate of `ThrottlerSleepMicroseconds` is printed as `N waited` (threads sleeping in throttlers, same unit as CPU); the bar turns yellow when it exceeds the CPU rate. The counter is still committed only after a sleep ends, so long sleeps appear as bursts.
Record the progress count at each flip of the stalled flag and draw the bar cell by cell in the color of the state that produced that progress. Counts, not cell positions, are stored, so terminal resize and growth of the total to read rescale correctly.
|
Workflow [PR], commit [1249810] Summary: ✅
AI ReviewSummaryThis PR teaches the client progress bar to surface query wait time from throttlers and workload I/O scheduler waits, and to preserve the wait/CPU history in the bar coloring across overlays, hidden-bar intervals, and byte-to-row carrier switches. I re-checked the current diff and every prior review thread against the current head, and I did not find any remaining correctness, concurrency, or regression-coverage issues that still reproduce in the code as written. Final Verdict
LLVM Coverage ReportMeasured on commit 1249810.
Changed lines: Changed C/C++ lines covered: 149/155 (96.13%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units22 translation units recompiled, 130 s compile time in total, 22 of them have a recent master baseline. |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Thanks! Looks good.
Except some confusion with the background color when rendering metrics at the left side. This is tolerable.
I've worried about the space these metrics used. But they shouldn't display most of the time.
A question - does the metric cover all stalls that our resource scheduler does? We can check with @serxa
|
It doesn't cover any stall due to workload scheduling. It only covers throttlers, which are not related to workloads currently. There are independent throttling for workload IO and preemption for CPU. CPU bottleneck is more tricky to track, probably not worth. Also we now have admission wait due to query slots allocation and/or pending memory reservation. These would be nice to show, but harder to implement as query is basically blocked even before ProcessList::insert. For on-demand compute we also have provisioning wait - similar to admission, but a different private repo story implementation-wise. |
|
For workload-based IO the total wait already exists as per-thread ProfileEvents that are streamed to the client, so we can add them to "waited" as-is:
Overall the feature is nice. I like it! Maybe later we can add other colors for CPU/Memory pressure situations. |
`colored_bar` treats every stored count in `bar_segments` as the first cell of its segment, but the first entry was seeded with `current_count`. The bar is rendered only after the query has already made progress, so the already-filled prefix `[0, current_count)` was never emitted until the stalled state flipped for the first time: an integral width rendered an empty bar, a fractional one only the trailing partial cell. Seed the first segment at 0 and add `05210_client_progress_throttler_waited`, which throttles a `MergeTree` read in `clickhouse-local` and checks that the bar starts with a full colored block right after the counters, that the `waited` figure is shown next to `CPU`, and that throttled cells are yellow. Co-Authored-By: Claude Fable 5.1 <[email protected]>
As suggested in the review, `SchedulerIOReadWaitMicroseconds` and `SchedulerIOWriteWaitMicroseconds` are already streamed to the client as per-query profile events, so they are summed into the same `waited` figure as `ThrottlerSleepMicroseconds`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 @serxa thanks, adopted in 976d8ce: Also merged |
…ited` `local_path` is derived from `CLICKHOUSE_TMP`, so it must not reach `bash` unquoted: a temporary directory with whitespace, glob characters or a leading `-` would make `rm -rf` and `--path` act on the wrong location. The path is now single-quoted (with embedded quotes escaped) everywhere it is sent to the shell, and the cleanup uses `rm -rf --`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 Both stress-test reds on 976d8ce are unrelated to this PR (client progress bar rendering only):
Also pushed: the |
|
Confirmed: #119814 covers that occurrence. Measured on the
One precision: for this carrier the test-side half of #119814 alone would also stop the firing, since 04878 now sets From #119814's own CI, in case it is useful: The |
`bar_segments` recorded every flip of the `stalled` state for the whole query, and `colored_bar` rescanned all of them on every repaint, so a throttled query whose `waited`/`cpu` ratio oscillates around the threshold made the repaint cost grow with the query duration. Now a flip without progress since the previous flip does not add a segment (the empty segment is dropped and the previous one continues), segments beginning in the same terminal cell are collapsed on every repaint (the cell keeps the count where it began and takes the later state), and neighbours of the same state are merged. The history is also not recorded when the bar is not going to be shown. The retained history and the work per repaint are bounded by the width of the bar. Co-Authored-By: Claude Fable 5.1 <[email protected]>
`bar_segments` was compacted in place at the current width of the bar, so a repaint while the terminal was temporarily narrow (or while the bar was hidden by the annotation) discarded transitions that were visible again once it was widened, recoloring already completed work with the latest state. The history is now compacted at a fixed resolution (`bar_history_resolution`, finer than any terminal), which keeps it bounded by that resolution instead of by the duration of the query, and rendering at the real width skips the ranges that begin in the same cell, so the cell takes the state of the last segment beginning in it, as before. The test no longer sends the environment-derived `CLICKHOUSE_TMP` path to the shell as text: the spawned `bash` inherits it as `CLICKHOUSE_LOCAL_PATH` and expands it inside double quotes, and the cleanup is done with `file delete`. Verified with a `CLICKHOUSE_TMP` containing a space and a single quote. Co-Authored-By: Claude Fable 5.1 <[email protected]>
When the resource usage annotation moves to the left, on top of the progress bar, its background was a single color taken from the current `stalled` state, so the completed prefix it covers lost its history: a query throttled early and CPU-bound past 50% was repainted green under the text. The annotation now takes its background per cell from `bar_segments`, like the rest of the bar. Co-Authored-By: Claude Fable 5.1 <[email protected]>
A hash join whose build side is read through `max_local_read_bandwidth` and whose probe side is CPU-bound gives a mixed history; once the annotation is rendered on top of the bar, it has to carry both background colors. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…shot `Progress` is updated concurrently and only piecewise atomically, so reading `total_rows_to_read` twice could make `current_count`/`max_count` be in rows while `count_in_rows` (and thus the carrier of `bar_segments`) is still bytes. Take all counts from one `Progress::getValues` snapshot. Also skip `05291_client_progress_cpu_of_shards_on_one_host` in the flaky check: the thread fuzzer's injected sleeps take away the CPU time of the shards, so the figure never reaches 3 CPU (it timed out in all five flaky check jobs). https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=118536&sha=d8c47f0a9a3d214ce1d8b08bb38c63f4fc870835&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29 ClickHouse#118536 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 Pushed 0a06953:
|
…e_host` The test profile of the CI server (`tests/config/users.d/limits.yaml`) sets `max_rows_to_read` to 20 million, so the query over `numbers(1000000000000)` failed at once with `TOO_MANY_ROWS` (seen in `query_log`: 8 runs, each ended after 8-37 ms with code 158), the progress bar never showed a CPU figure, and the test timed out after 60 s in `Stateless tests (arm_binary, sequential)`. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=118536&sha=0a069539f4c1ed04c0d3df7946f8b9b291306820&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20sequential%29 PR: ClickHouse#118536 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 Pushed aac7c5b:
|
…gress` `writeProgress` read the CPU usage, the waited usage, and the per-host aggregates through separate getters, each taking and releasing `profile_events_mutex`. A concurrent `updateThreadEventData` could then make `cpu_usage` and `waited` come from different packets, and the torn `stalled` state was recorded in `bar_segments` permanently. Now `getProfileSnapshot` computes all of them under one lock. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 Pushed e2071d5, which adopts the bot thread: The reds on aac7c5b are unrelated to this client-only change:
@groeneai, investigate the failures: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118536&sha=aac7c5bde19b4a1c2d714e13d18a95a08f38cb0f&name_0=PR and provide a fix in a separate PR. If the fix is already in progress, link it here. |
|
Both reds have fixing PRs:
|
…leEvents` A packet can contain several rows for one `host_name` (e.g. several shards on one server), which already required summing `UserTimeMicroseconds` and `SystemTimeMicroseconds`. Sum the current memory and temporary-disk usage the same way so the figures stay comparable with `CPU`, and take the maximum of the peak memory usage, which is not additive over time. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`MemoryTrackerUsage` and `TemporaryDataOnDiskUsage` are `GAUGE` rows, and `getProfileEvents` appends all queued remote blocks into one packet, so summing them multiplied one source's usage by the number of coalesced snapshots. Without a per-source identifier the client cannot tell queued snapshots from concurrent shards on one host, so take the maximum instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged The two reds on 83525bc are server-side and unrelated to this PR:
@groeneai, please investigate the |
|
Investigated. The fatal log names This is the same row-policy route as the It is not the route closed with #106039: that issue is the CI matcher for this message on any stream, and its fix #114916 covered a parameterized view in an The fix is in progress: #114955 (mine, open). Its description names this |
|
Ok. Now the IO waits in the scheduler are included. But do we have other throttling in the scheduler, e.g., network, CPU wait? Should we also include waits on the memory tracker overcommit? |
|
I think that's enough for this PR, other things are more tricky than simple counters. |
…ress Master's client progress rework (ClickHouse#118536, ClickHouse#123549) moved the CPU, memory and temp-disk reads of `writeProgress` into one `getProfileSnapshot()` call under `profile_events_mutex` and added a "waited" meter. The IO rate now comes from the same snapshot (`ProfileSnapshot::io_rate`), so it is read together with the other values, and the IO counters are summed next to the other `INCREMENT` rows in `ClientBase::onProfileEvents`. The Web UI notebook mode (ClickHouse#115378) moved the resource-meter state from the tab to the cell, so both `payloadMeter` callbacks now add to `cell.resources`. Left as merged, the live one would read `tab.resources`, which no longer exists, and throw on the first result packet. 04548 greps the new spelling and keeps master's new checks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ground-queries Master's client progress rework (ClickHouse#118536, ClickHouse#123549) replaced the private `getCPUUsage()` with one `getProfileSnapshot()` for `writeProgress` and added a "waited" meter. Background jobs still read the current CPU rate, so the public `getCPUUsage()` is kept beside `getAverageCPUUsage()`, and the per-host CPU totals keep accumulating next to master's waited sum. The flush callback now clears the progress only when the output reaches the terminal (master), and still checks `tty_buf` under `tty_mutex` (this branch), because a detached job can swap the output while a query runs. 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):
Show throttler and workload IO scheduler wait time in the client progress bar (
ThrottlerSleepMicroseconds,SchedulerIOReadWaitMicrosecondsandSchedulerIOWriteWaitMicrosecondsare summed into thewaitedfigure, and the stalled sections of the bar are colored yellow).Later, other events can be added (that's why "waited" and not "throttled")
Demo - https://asciinema.org/a/1Us5t9dAj4nOPGQJ
Workflow [PR]
Sync PR [sync-upstream/pr/118536]
Version info
26.10.1.1336-master(included in26.10and later)