Repository navigation
Show live disk I/O throughput in clickhouse-client's progress line - #116577
valerypetrov wants to merge 89 commits into
Conversation
Extend the live resource-usage segment of the progress line with disk I/O read/write rates, following the exact mechanism already used for CPU/memory: - `ClientBase::onProfileEvents` extracts the OS-level `OSReadBytes`/`OSWriteBytes` counters (already streamed per query, per host, as interval deltas) into `ThreadEventData`. - `ProgressIndication` feeds them into two `EventRateMeter`s (same 2 s window as the CPU meter) and renders `<rate>/s read` / `<rate>/s write` in `writeProgress`. The counters measure actual block-device I/O (page-cache reads are not counted), matching the intent of spotting I/O-bound queries live. On non-Linux servers the counters stay zero and the segment simply does not appear. No server or protocol change; the feature rides the existing ProfileEvents stream. Closes: ClickHouse#116565
The first version asserted `OSReadBytes`/`OSWriteBytes` using `numbers()` (in-memory, no reads) and `INSERT INTO FUNCTION null()` (no writes), so both counters stayed zero and the test failed deterministically; the `OSTYPE` guard also failed on macOS instead of skipping. Rewrite around a real `MergeTree` table: a direct-I/O `SELECT` for the read counter and an `fsync_after_insert` `INSERT` for the write counter, with a `no-darwin` tag (the counters are Linux-only).
|
Workflow [PR], commit [3dd16e5] Summary: ✅
AI ReviewSummaryAdds aggregate IO throughput to Missing context / blind spots
Final VerdictStatus: ✅ Approve |
|
This is interesting! Three things (before looking into the code):
|
|
@alexey-milovidov , Looks okay on my computer(please see the screenshot). Those ideas are great. I've added features as you asked. I was also thinking about the cost of query in $(when you query the ClickHouse with data stored in S3/Azure).
|
|
Let me also rename |
Broaden the progress line's resource segment from disk-only device I/O to `IO` (block devices + object storage) and network, per review feedback: - IO read = `OSReadBytes` + `ReadBufferFromS3Bytes` + `ReadBufferFromAzureBytes`; IO write = `OSWriteBytes` + `WriteBufferFromS3Bytes`. - Network read/write = `NetworkReceiveBytes`/`NetworkSendBytes`. - Rendered as `<rate>/s read IO`, `<rate>/s write IO`, `<rate>/s net read`, `<rate>/s net write` via two more `EventRateMeter`s, mirroring the CPU meter. - The Web UI (play.html) real-time resource meters now fold the same events and render the identical fields, keeping the two consistent. Rewrite the streaming test per the direct-IO precedent (assert `OSReadBytes` > 0 via `query_thread_log` with `pread_threadpool` and a full part) so it is reliable on Linux CI. Closes: ClickHouse#116565
|
If we have all of these: disk read/write, net read/write, it will be messy. Let's use just one number: |
Better to postpone that. You can count GET/PUT/LIST requests, but it depends on the storage tier (e.g., Glacier), and the service type (e.g., Express), and who pays for it also depends (e.g., requester pays), and if it is even AWS (e.g., Cloudflare R2), and it will also not show network cost, and the network cost depends on the region, and even on tiny details like if you misconfigured and accidentally use Internet Gateway and NAT for S3. So you'd better not do this. |
Yeah, it would be hard to implement. I agree. Let's postpone that. But as an end-user, it would be nice to have, especially in order to fix some super inefficient queries. (Look, you spent on this query $XX, but you could save some money if you rewrote it.) |
Per review: sum all IO counters (block-device reads/writes and object-storage reads/writes) into one `IO` meter, rendered as `<rate>/s IO`. Network read/write stay separate. Web UI consolidated identically.
Per review: one `IO` number instead of separate disk-read/write and net-read/write meters. IO sums block-device reads/writes (`OSReadBytes`/`OSWriteBytes`), object-storage reads/writes (S3, Azure), and ClickHouse's network traffic (`NetworkReceiveBytes`/`NetworkSendBytes`), rendered as `<rate>/s IO`. Web UI consolidated identically.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units28 translation units recompiled, 134 s compile time in total, 28 of them have a recent master baseline. |
The IO meter summed OS, S3 read/write, Azure read, and network bytes, but Azure uploads only counted requests, so Azure-backed inserts showed 0 B/s IO. Add WriteBufferFromAzureBytes, incremented where the write buffers and the copy helper actually push data (Upload/StageBlock/Append), mirroring WriteBufferFromS3Bytes, and include it in the client and play.html sums.
The query_log lookup matched any recent direct-io SELECT in the database; pin it with log_comment. Add an expect test that drives a real pty (wide, so the profiling suffix fits) and asserts '<rate>/s IO' appears in the progress line while a paced SELECT streams ~30 MB to the client, covering ClientBase::onProfileEvents -> ProgressIndication::writeProgress. FORMAT Null would not do: the server sends no data for it, so the stream goes to INTO OUTFILE /dev/null, paced by sleepEachRow per 1 MB block.
The network expect test and the query_thread_log check together still let the disk counters silently drop out of ThreadEventData::io_bytes. The new expect test reads a 44 MB table with direct IO throttled to ~10 MB/s under FORMAT Null, so network traffic stays at KB/s and the MB-scale '/s IO' the test expects can only come from OSReadBytes flowing through onProfileEvents into the meter. Two constraints found while validating: writeProgress renders the profiling suffix for known-total queries only when the query was under half done at 0.5 s (the read throttler's initial burst must not cover half the table), and the client redraws ':) ' while echoing a sent query, so each step waits for its completion marker before the prompt.
The read and network carriers were proven end-to-end, but every write-side event could drop out of the meter's sum with all tests green. The new expect test INSERTs ~30 MB of incompressible parts, paced to one 1 MB part per 0.1 s by source sleeps with squashing disabled, entirely server-side - the client connection stays at KB/s, so the MB-scale '/s IO' the test expects can only come from OSWriteBytes reaching the meter through onProfileEvents.
OSWriteBytes is not a stable carrier for this test: its event contract says buffered writes may be accounted asynchronously, so a local-disk INSERT can legitimately keep it at 0 until the query is done. The S3 write counter is deterministic - counted per part as the query uploads - so the INSERT now goes to the minio endpoint as forced 5 MB multipart parts (a single PutObject at finalize would be one burst delta, which the rate meter's heating discards). The S3 upload bypasses the native-protocol socket buffers, so the client connection stays at KB/s and the MB-scale '/s IO' can only come from the object-storage write counter - which also covers the write literal family this PR extended.
CI showed every run of the test dying with EntityTooSmall at CompleteMultipartUpload: s3_min_upload_part_size = 5000000 is 4.77 MiB, just under the 5 MiB minimum S3 enforces for non-final parts. Parts are now 6 MB. Also disable parallel part upload so the parts are sent by the query thread itself - its per-interval deltas are what the client meter consumes, while the IO thread pool's contribution is not guaranteed to reach the streamed ProfileEvents mid-query (CI rendered only the KB/s connection trickle while the pool was uploading). 300 rows instead of 400 to stay well inside the expect timeout on loaded flaky-check runners, which paced the source at a tenth of the design speed.
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=116577&sha=latest&name_0=PR ( |
|
Acknowledged. I'm investigating the |
|
The fix is in #128385 (test-only). With randomized |
With a randomized max_insert_threads the blocks of INSERT ... RETURNING may be processed by different threads, so the result rows can arrive in any order (CI saw 3,1,2). The test checks the packet framing, not the order, so sort the output. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ress Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The six `select JSON*Paths(arrayJoin(json.a[])) from test` queries had no ORDER BY, so they asserted the physical read order of the merged part. With a randomized `index_granularity = 1` the merged part (10, then 15 rows) has one granule per row. On a remote disk the minimum read task is `merge_tree_min_read_task_size` = 8 marks (the `_for_remote_filesystem` row/byte minimums default to 0), so the part is read as two tasks, [0, 8) and [8, N), whose streams are united without order; the short task usually finishes first and its rows are printed first. That is the failure seen in `Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel)` on PR ClickHouse#116577 (172 of 174 same-settings reruns failed). Only release builds can draw that granularity: debug and sanitizer builds draw it from [100, 65536]. Order each SELECT by its own result (`order by all`) and reorder the reference within each section accordingly. The per-section contents are unchanged, and since every row carries exactly one path, those multisets still pin which path is dynamic and which is in shared data. `order by _part_offset` is not usable here: the planner evaluates the JSON*Paths functions after that sort, on a JSON column re-assembled from the two read tasks' chunks, which changes the reported layout (the `c` paths become dynamic). With `order by all` the sort key is the function result, so the function still runs on each read chunk before the sort. Related: ClickHouse#116577 Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/IO/AzureBlobStorage/copyAzureBlobStorageFile.cpp
|
🕵 Merged the latest |
|
🕵 Fixed the |
…ress Bring the branch up to date with master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The distributed leg failed in the debug and tsan jobs: a 4 KiB OSWriteBytes of the server arrived in the last ProfileEvents packet and the meter showed it as a short spike (41 MB/s), which the test took for counted service traffic. The idle leg failed on any IO term at all, so it was exposed to the same stray write. Service traffic counted as IO is sustained, a stray write decays. So both legs now fail only when every progress line after 200 of the 300 rows shows 10 KB/s or more, and interactive_delay of 10 ms raises the service traffic to about 100 KB/s (idle) and 40 KB/s (distributed) so it stays far above a stray write. The test takes about 11 seconds and went over the 15 second limit for new tests in the Fast test, so it is tagged no-fasttest. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged the latest |
A server sends the blocks of a distributed INSERT with Connection::sendData, which counted no native data bytes, so the initiator's live IO rate stayed at zero during the upload. Connection now counts the Data packets with rows it sends, and the prepared ones, to NativeProtocolDataBytes, like the server counts its result packets. In Play the IO rate was sampled only while the cell's tab was shown, so a query that stopped moving data kept its old rate when its tab was opened again. A background cell now samples its IO rate on its own clock. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The harness gained this scenario, but the pinned SCENARIOS list did not, so the drift check failed in every integration job. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The IO meter of `clickhouse-client` and the Play UI sums plain `NetworkSendBytes` and `NetworkReceiveBytes` again, and the `IO` term is shown only when the rate is at least 1 MB/s, so the progress-reporting packets themselves do not show up. This removes the `NativeProtocolDataBytes`, `NativeProtocolDataReceiveBytes` and `FramingServiceBytes` profile events, the chunk framing byte counting in `ReadBufferFromPocoSocketChunked`, and the decoded payload metering in the Play UI, together with the tests that pinned them. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
🕵 Merged the latest I ran the PR's tests locally on this merge (the server binary was built from a tree whose C++ differs from it only in comments): I also updated the PR description and the changelog entry: they still listed the removed Optional and not applied here: now that the byte corrections are gone, the Play UI's IO rate comes only from the |
|
📊 Cloud Performance Report ✅ AI verdict: No query changed in a way this PR could cause. The only flagged query is clickbench Q31: +13.4% (246 ms vs 217 ms). That falls inside master's current range for this query (195–266.5 ms), so it was already marked inconclusive, and the query has a noisy history on master. This is consistent with the diff, which only touches the client's progress line and play UI IO meter, adds Azure write byte counters, and changes profile-event flushing while the server waits for INSERT data. Q31's SELECT GROUP BY runs none of that code, so there is no reason to contest the result. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
|
🕵 Merged the latest
@groeneai, investigate the failure: |
|
Acknowledged. I'm investigating |
|
I could not open the private run, so this is from the test and a local reproduction. The four missing rows are the last block of the test, which reads the output divisor from the Fix: #133636. The test now reads the line from the server logs the client receives ( |

Closes: #116565
clickhouse-client's live progress line reports CPU, memory, and temp-disk-spill usage during query execution, but has no visibility into I/O throughput — useful for spotting an I/O-bound query in real time, the way the CPU figure helps spot a CPU-bound one.This adds a live IO rate (e.g.
12.40 MB/s IO) to the same resource-usage segment, following the exact mechanism already used for CPU and memory. The rate is the plain sum of the byte counters of everything the query moves: block devices (OSReadBytes/OSWriteBytes), object storage (ReadBufferFromS3Bytes/WriteBufferFromS3Bytes,ReadBufferFromAzureBytes/WriteBufferFromAzureBytes), HTTP (ReadWriteBufferFromHTTPBytes/WriteBufferFromHTTPBytes), and network (NetworkSendBytes/NetworkReceiveBytes, plusStreamingExchangeSendBytes/StreamingExchangeReceiveBytesfor the streaming exchanges of a distributed plan, which the former two do not count).The network counters also include the packets of the progress reporting itself (
Progress,ProfileEvents), which is a small amount. There are no corrections for that: a rate below 1 MB/s is simply not shown.ClientBase::onProfileEventssums these counters intoThreadEventData. They are already collected per thread, aggregated into the query's counters, and streamed to the client as per-interval deltas on the existing ProfileEvents channel (send_profile_events, on by default) — no protocol change.ProgressIndicationfeeds the sum into anEventRateMeter(same 2-second window as the CPU meter) and renders it inwriteProgresswhen it is at least 1 MB/s.play.html) shows the same<rate>/s IOterm from the same counters, with the same 1 MB/s threshold.AzureUpload), so a newWriteBufferFromAzureBytesprofile event is added, incremented where the Azure write buffers and the copy helper actually push data (Upload/StageBlock/Append), mirroringWriteBufferFromS3Bytes.INSERT ... SELECTruns as a completed pipeline whose interactive callback already streams ProfileEvents everyinteractive_delay; for inserts fed by client data, the receive loop now also flushes profile events on the same cadence while waiting for the next packet (previously only per received packet and once at the end).The OS-level counters measure actual block-device I/O (page-cache reads are not counted) and come from Linux taskstats, so they stay zero on non-Linux servers; the object-storage and network counters are platform-independent. Old servers (< the incremental-ProfileEvents protocol version) are unaffected.
Tests: three expect tests drive a real pty and assert the
<rate>/s IOterm in the live progress line, one per carrier class:05026_client_io_progress_line.expect(network — an idle query, whose only traffic is the progress reporting, never shows a rate below 1 MB/s, while a paced query that streams ~30 MB to the client shows its rate; runs on every platform),05026_client_io_progress_line_disk.expect(disk reads — a direct-I/O read throttled to ~10 MB/s underFORMAT Nullkeeps network at KB/s, so the MB-scale rate can only come fromOSReadBytes), and05026_client_io_progress_line_write.expect(object-storage writes — a pacedINSERTuploads ~30 MB to the minio endpoint as forced 6 MB multipart parts, and a further progress frame is required after the matched one, proving the rate was rendered mid-query).05026_client_disk_io_progress_streaming.sql,05026_client_io_network_receive_http_bytes.sh,05026_client_io_streaming_exchange_bytes.shand05026_client_io_azure_write_bytes.shcheck that the counters of each carrier reach the client's ProfileEvents stream;05026_insert_profile_events_stall_tcp.shand05026_insert_returning_stall_tcp.shcover the periodic flush while anINSERTwaits for client data; the Play UI's meter is covered by04548_play_ui_framing_fallbacks.shand by scenarios oftest_play_image_previewandtest_play_notebook.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
clickhouse-client's live progress line and the Play UI now show the query's IO throughput (e.g.12.40 MB/s IO) — disk, object storage, and network combined — alongside the existing CPU and memory figures, when it is at least 1 MB/s. Added the profile eventWriteBufferFromAzureBytes(bytes written to Azure blob storage).Workflow [PR]
Sync PR [sync-upstream/pr/116577]