Skip to content

Show throttler wait time in the client progress bar - #118536

Merged
alexey-milovidov merged 46 commits into
ClickHouse:masterfrom
azat:client-progress-throttling
Oct 2, 2026
Merged

alexey-milovidov merged 46 commits into
ClickHouse:masterfrom
azat:client-progress-throttling

Conversation

@azat

@azat azat commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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, SchedulerIOReadWaitMicroseconds and SchedulerIOWriteWaitMicroseconds are summed into the waited figure, 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

  • Merged into: 26.10.1.1336-master (included in 26.10 and later)

azat added 2 commits September 7, 2026 12:30
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.
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1249810]

Summary: ✅


AI Review

Summary

This 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
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit 1249810.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.80% 79.80% +0.00%

Changed lines: Changed C/C++ lines covered: 149/155 (96.13%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Sep 7, 2026
Comment thread src/Common/ProgressIndication.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-cli clickhouse-client (interactive CLI) and client library. label Sep 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 12498100a with master 31d9e00c8 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

22 translation units recompiled, 130 s compile time in total, 22 of them have a recent master baseline.

Job report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@alexey-milovidov alexey-milovidov self-assigned this Sep 12, 2026
@serxa

serxa commented Sep 12, 2026

Copy link
Copy Markdown
Member

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.

@serxa

serxa commented Sep 12, 2026

Copy link
Copy Markdown
Member

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:

  • SchedulerIOReadWaitMicroseconds
  • SchedulerIOWriteWaitMicroseconds

Overall the feature is nice. I like it! Maybe later we can add other colors for CPU/Memory pressure situations.

alexey-milovidov and others added 3 commits September 13, 2026 10:27
`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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @serxa thanks, adopted in 976d8ce: SchedulerIOReadWaitMicroseconds and SchedulerIOWriteWaitMicroseconds are now summed into the same waited figure as ThrottlerSleepMicroseconds. Admission waits (query slots, memory reservation) and CPU preemption are left for a follow-up, since they happen before the query is in ProcessList or need a different accounting.

Also merged master (the branch was about 5300 commits behind; the 04648/04340 distributed-plan reds were fleet-wide on 2026-09-06..09 and are fixed there) and addressed the AI review finding about the first progress bar history segment, with a regression test.

alexey-milovidov and others added 2 commits September 13, 2026 23:43
…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Both stress-test reds on 976d8ce are unrelated to this PR (client progress bar rendering only):

Also pushed: the local_path in 05210_client_progress_throttler_waited.expect is now shell-quoted (with rm -rf --) as the AI review requested, the changelog entry mentions the IO scheduler waits, and master is merged again.

Comment thread src/Common/ProgressIndication.cpp Resolved
@groeneai

Copy link
Copy Markdown
Collaborator

Confirmed: #119814 covers that occurrence.

Measured on the Stress test (arm_tsan) artifacts at 976d8cec (fatal thread 8461, query bb8118b5-c948-4735-91dc-54a99fa3bf31, report):

  • The carrier is 04878_distributed_plan_shuffle_bucket_order_promise.sql-test_5: that is the log_comment of the aborting query, in fatal.log's changed-settings dump and in query_log.tsv independently.
  • Its settings there are enable_cascades_optimizer = true, make_distributed_plan = true, distributed_plan_force_shuffle_aggregation = true, distributed_aggregation_memory_efficient = true, enable_memory_bound_merging_of_aggregation_results = true, group_by_two_level_threshold = 10000, group_by_two_level_threshold_bytes = 1, and allow_experimental_parallel_reading_from_replicas = 0, so the parallel-replicas carriers of this message are excluded.
  • The abort is initiator side, MergingAggregatedMemoryEfficientTransform.cpp:63 reached from tryPushTwoLevelData().
  • The binary is 1f857f3cabd2bd4fa66df47fb561712f918c9725 (praktika's merge of 976d8cec into master 00260f9813a7568f8d63a36e946cff4640954af5), and Do not use the distributed-plan Shuffle aggregation when bucket order is promised #116446's merge commit 3df00505b0f81beebdeceadf67a1bcf798c2bb16 is an ancestor of it, so the rule-based guard was already in that build and the Cascades plan of 04878 is the only path left. That is what Keep the bucket-order promise of a shard aggregation in the Cascades optimizer #119814 changes, and Keep the bucket-order promise of a shard aggregation in the Cascades optimizer #119814 itself is 6 hours younger than the build, as expected for a pre-fix firing.

One precision: for this carrier the test-side half of #119814 alone would also stop the firing, since 04878 now sets enable_cascades_optimizer = 0 and 05210 pins the Cascades plan instead, so the rule change is what covers the remaining Cascades plans rather than this test.

From #119814's own CI, in case it is useful: Stateless tests (amd_debug, flaky check) on 7b236cf has one 05210 run at 185s failing with Test runs too long (> 180s), against 249 passing runs averaging 42s, so the new test is marginal against that limit in debug with random settings (report).

The arm_asan_ubsan attribution is right as well: #119810 is mine and open.

`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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai thanks for confirming both attributions. Also pushed c654878 for the AI review finding: the progress bar colour history is now bounded by the width of the bar (empty segments dropped at the flip, same-cell segments collapsed on repaint, no recording while the bar is hidden).

Comment thread src/Common/ProgressIndication.cpp Resolved
`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]>
Comment thread src/Common/ProgressIndication.cpp Resolved
alexey-milovidov and others added 2 commits September 14, 2026 16:22
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]>
Comment thread src/Client/ClientBase.cpp Resolved
…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pushed 0a06953:

  • Adopted the bot thread on ProgressIndication.cpp: the progress bar counts now come from one Progress::getValues snapshot.
  • All five flaky check jobs on d8c47f0 failed only on 05291_client_progress_cpu_of_shards_on_one_host, which timed out at 60 s. The flaky check runs with the thread fuzzer, and its injected sleeps take CPU time away from the shards, so the figure never reached 3 CPU. The test is now tagged no-flaky-check. It passed in the targeted ASan jobs and in the regular stateless jobs.

alexey-milovidov and others added 2 commits October 1, 2026 05:16
…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pushed aac7c5b:

  • The only red on 0a06953, Stateless tests (arm_binary, sequential), was 05291_client_progress_cpu_of_shards_on_one_host, caused by the test itself. The query_log of the job shows that every run of the query failed within 8-37 ms with TOO_MANY_ROWS, because the test profile (tests/config/users.d/limits.yaml) sets max_rows_to_read to 20 million and the query reads numbers(1000000000000). So the progress bar never showed a CPU figure, and the expect timed out after 60 s. The test now passes --max_rows_to_read 0.
  • Merged master (clean). ClientBase.cpp and ProgressIndication.cpp compile.

Comment thread src/Common/ProgressIndication.cpp Resolved
…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pushed e2071d5, which adopts the bot thread: writeProgress now takes one profile_events_mutex snapshot, so the stalled state can no longer be torn across packets. Both TUs compile.

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.

@groeneai

groeneai commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Both reds have fixing PRs:

  • Stress test (arm_release), hung check: Stop the Freeform structure search at the query's memory and time limits #123238 (opened today). In this run's stress log, two 05258_freeform_schema_inference_search_bound queries (desc file(..., 'Freeform') settings max_memory_usage = 150000000) were still inside the structure search when the log ends, 44 and 39 minutes after they started, despite max_execution_time = 60 and about 50 KILL QUERY attempts from the stress runner. That kept the server at its 42 GiB limit. The search does not stop at the memory limit, the time limit or KILL, and with a randomized compatibility below 26.10, input_format_freeform_max_search_steps is 0, so nothing bounds it. Stop the Freeform structure search at the query's memory and time limits #123238 adds those checks to the search. The same queries are behind the recent master hung checks on arm_release (d6021c7b43d5) and arm_debug (067e8806ad1a).
  • Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel), time limit: Split the two un-batched amd_llvm_coverage s3 parallel stateless jobs into 2 batches #116209 splits this job and its AsyncInsert sibling into 2 batches each. It has conflicted with master since 2026-09-12; I'm merging master into it now, regenerating the workflows from the merged config.

Comment thread src/Client/ClientBase.cpp Resolved
…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pushed f6e517d, which addresses the last bot thread: the same-host RAM and disk gauge rows are now summed in onProfileEvents, consistent with CPU/waited, and the peak takes the maximum. ClientBase.cpp compiles. Thanks @groeneai for linking #123238 and #116209 for the two unrelated reds.

Comment thread src/Client/ClientBase.cpp Resolved
`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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master (1249810); the change is still client-only, and clickhouse builds.

The two reds on 83525bc are server-side and unrelated to this PR:

@groeneai, please investigate the Coordination mode mismatch failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118536&sha=83525bcc66d59df638c74fd393d36a78a55b95cd&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29 and fix it in a separate PR. If a fix is already in progress, link it here.

@groeneai

groeneai commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Investigated. The fatal log names SELECT id, department FROM t_mt_index_rp ORDER BY id from 04891_mergetree_index_respects_row_policy (log_comment), run with serialize_query_plan = 1 and parallel replicas over a non-replicated MergeTree.

This is the same row-policy route as the Stress test (amd_debug) red on 87c5e48 (#112891), with the other symptom. The initiator's local read applies the policy department = 'engineering', which fixes the first sorting key column, so it reads ORDER BY id in order and creates the coordinator as WithOrder. The replicas get the serialized plan without the policy, plan a default read and announce Default, and getOrCreateCoordinator throws on the mismatch.

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 IN subquery.

The fix is in progress: #114955 (mine, open). Its description names this got Default, expected WithOrder error. It is not merged, so this run's tree could not contain it. It conflicts with master since #119387 merged yesterday; I'm merging master into it.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Thanks @groeneai: the Coordination mode mismatch red comes from the row-policy route in parallel replicas, and #114955 will fix it. It is server-side and unrelated to this client-only change. CI on 1249810 has no failures so far, and some jobs are still running.

@alexey-milovidov

Copy link
Copy Markdown
Member

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?

@serxa

serxa commented Oct 2, 2026

Copy link
Copy Markdown
Member

I think that's enough for this PR, other things are more tricky than simple counters.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 2, 2026
Merged via the queue into ClickHouse:master with commit 816baa2 Oct 2, 2026
149 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 2, 2026
valerypetrov added a commit to valerypetrov/ClickHouse that referenced this pull request Oct 3, 2026
…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]>
valerypetrov added a commit to valerypetrov/ClickHouse that referenced this pull request Oct 3, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-cli clickhouse-client (interactive CLI) and client library. pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants