Skip to content

Distributed query plan: serialize exchange data on every stream - #119067

Merged
davenger merged 19 commits into
masterfrom
shuffle-exchange-parallelism
Sep 14, 2026
Merged

davenger merged 19 commits into
masterfrom
shuffle-exchange-parallelism

Conversation

@davenger

@davenger davenger commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

When a distributed query plan sends data to other nodes, each destination has one exchange sink, and that sink serialized and compressed all the data for its destination on one thread. With few destinations this becomes the bottleneck of the sending task: with 3 workers and 3 shuffle buckets, the reader task's 3 sinks were busy most of the time while its read streams waited on them.

Now the exchange serializes on every pipeline stream before the streams of a destination are merged into its sink, and the sink only sends the ready packets. This applies to the shuffle, the unsorted gather and the broadcast; the sorted gather has to merge first, so it stays as it was. The broadcast serializes each chunk once and its sinks share the packet instead of each serializing the same chunk. The bytes on the wire are unchanged. In-memory and file-based exchanges keep working with plain chunks; only the stream layout of the keyless scatter changed for them, to the one the keyed scatter already used.

Changelog category (leave one):

  • Experimental Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Distributed query plans (make_distributed_plan) now serialize the data sent between nodes on all threads of a task instead of one thread per destination. This removes a bottleneck when a query runs on a small number of workers.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/119067]

Version info

  • Merged into: 26.9.1.1466 (included in 26.9 and later)

@clickhouse-gh

clickhouse-gh Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4a2b779]

Summary: ✅


AI Review

Summary

This PR moves streaming-exchange serialization from a single destination sink onto per-stream transforms, lets broadcast destinations share one serialized packet, adds transport/back-pressure profile events, and replaces the deleted layout tests with loopback transport and stateless topology coverage. I did not find a remaining correctness, compatibility, or performance-contract issue in the current code.

Missing context / blind spots
  • ⚠️ The full PR workflow and Build (arm_tidy) check were still pending when I reviewed this on 2026-09-13, so this review is based on the current diff, the full prior discussion, and the completed fast/style/build-profile checks.
Final Verdict

✅ No new review findings in the current code.

LLVM Coverage Report

Measured on commit 4a2b779.

Metric Baseline Current Δ
Lines 89.00% 89.00% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.40% 81.40% +0.00%

Changed lines: Changed C/C++ lines covered: 597/612 (97.55%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-experimental Experimental Feature label Sep 9, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-distributed Distributed table engine & query routing across shards (sharding/load balancing). label Sep 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 39 queries analysed

This PR reworks the distributed-plan streaming exchange (serialization moved onto per-stream transforms, a new send-queue in the exchange sink, plus new profile events and metrics). None of that code runs for a standard single-node ClickBench query. The one flagged row, Q34 at -5.2%, was already suppressed deterministically as within master's current variance band, and the diff gives no plausible mechanism to move it, so it reads as noise rather than a PR effect. No real regressions or improvements are attributable to this change.

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 961b0abc-b2c9-45f2-95f5-fa6e6721fb50
  • MIRAI run: f419b34a-ab57-4d47-a697-4b4d23bf7af6
  • PR check IDs:
    • clickbench_11667_1789309810
    • clickbench_11673_1789309810
    • clickbench_11679_1789309810
    • tpch_adapted_1_official_11690_1789309810
    • tpch_adapted_1_official_11701_1789309810
    • tpch_adapted_1_official_11739_1789309810

@clickhouse-gh

clickhouse-gh Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 4a2b779b6 with master c287fac2b (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.

Object file sizes

32 object files changed (+289.71 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/QueryPlan/FillingStep.cpp.o 158.83 KiB 270.11 KiB +111.29 KiB (+70.07%)
src/CMakeFiles/dbms.dir/Server/DistributedQuery/StreamingExchangeSerializingTransform.cpp.o new 83.64 KiB +83.64 KiB
src/CMakeFiles/dbms.dir/Server/DistributedQuery/StreamingExchangeProtocol.cpp.o 64.11 KiB 103.63 KiB +39.52 KiB (+61.65%)
src/CMakeFiles/dbms.dir/Core/SortDescription.cpp.o 204.89 KiB 221.96 KiB +17.07 KiB (+8.33%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

861 translation units recompiled, 6175 s compile time in total, 860 of them have a recent master baseline.

Symbol sizes
Binary Symbol Master PR Δ
programs/clickhouse ProfileEvents::global_counters_storage 12.25 MiB 12.38 MiB +128.00 KiB (+1.02%)
programs/clickhouse-keeper ProfileEvents::global_counters_storage 12.25 MiB 12.38 MiB +128.00 KiB (+1.02%)

Job report

A round-robin resize to `max_threads` multiplies the partial aggregation tables and their merge.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@davenger davenger changed the title Distributed query plan: serialize exchange data on every stream and aggregate shuffled data on all threads Distributed query plan: serialize exchange data on every stream Sep 10, 2026
Comment thread src/Common/ProfileEvents.cpp Resolved
…y closes and broadcasts

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@CheSema CheSema self-assigned this Sep 14, 2026
@davenger
davenger added this pull request to the merge queue Sep 14, 2026
Merged via the queue into master with commit 7f4f875 Sep 14, 2026
176 checks passed
@davenger
davenger deleted the shuffle-exchange-parallelism branch September 14, 2026 14:03
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 14, 2026
@clickhouse-gh clickhouse-gh Bot added comp-distributed-query-exchange Distributed Query Execution with Exchange operators: cloud-native query distribution using stream... and removed comp-distributed Distributed table engine & query routing across shards (sharding/load balancing). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-distributed-query-exchange Distributed Query Execution with Exchange operators: cloud-native query distribution using stream... pr-experimental Experimental Feature 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.

4 participants