Repository navigation
Conversation
…roadcasts Combine contiguous Arrow IPC inputs in four ordered groups. Keep this opt-in and fall back to serial assembly when driver headroom, the schema or the resulting wire size rules out the split.
Arrow checks its process-wide per-vector cap while sizing a fixed-width vector. Treat a refusal there like an oversized append. Exercise the actual limit in an isolated JVM and verify the original streams remain available to serial fallback.
Check cancellation between input streams even when a parallel attempt retries serially. Exercise admission, cancellation with live buffers, cleanup and reuse of the driver slot. Explain the cost of combining shared batches in each join task.
sunchao
marked this pull request as ready for review
December 5, 2026 00:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
No separate issue is linked yet. This draft tracks the proposal.
Rationale for this change
The driver combines small compressed Arrow IPC streams before broadcasting a hash join build. Combining them saves each consuming task from opening a reader per input batch, but a fragmented build can leave the driver decoding, appending and encoding on a single thread while the probe waits. Producer batching can reduce the number of inputs for certain shuffle reads. File scans and other producers can still deliver thousands of streams.
What changes are included in this PR?
Add an opt-in setting,
spark.comet.exec.broadcastExchange.parallelCoalesce.enabled. One exchange per driver can combine four contiguous groups of small streams concurrently. Workers use the existing Arrow coalescer, preallocate fixed-width destination vectors and emit their streams in input order. The broadcast format is unchanged.The first version targets hash broadcasts with at least 16 streams and an estimated 64 MiB of INT, BIGINT, FLOAT, DOUBLE or BOOLEAN data. It checks estimated driver headroom, limits Arrow allocations separately in each worker and avoids splits with expensive per-stream rounding. A worker allocator refusal, a schema mismatch or an over-limit combined wire size leaves the original inputs available for ordinary coalescing. Other failures propagate after all workers exit.
The setting defaults to false. The driver checks cancellation during parallel work, between input streams on serial retry, and before publishing the broadcast. It joins workers before releasing the driver slot. The exchange metric
numParallelCoalesceGroupsreports four for a selected parallel result and zero for ordinary coalescing.Driver heap checks are estimates. Each worker allocator limit covers Arrow buffers only. Even with shared executor decoding, DataFusion can copy multiple batches into one build batch per concurrent hash join task. For the 96 MiB value payload below, eight concurrent tasks could allocate about 768 MiB of extra value buffers on one executor. This estimate excludes validity bits and hash tables. The benchmark did not measure peak memory or network traffic across executors.
How are these changes tested?
All four focused
UtilsSuitetests passed. They cover nulls, order, schema mismatch, allocator refusal and a vector capacity failure in a separate JVM with a 64 KiB limit. The new test goes through production admission, cancels while workers own buffers, verifies allocator usage returns to baseline and reacquires the slot for a four-group exchange. It forces serial retry at the wire limit, verifies cancellation during that retry and checks that a normal retry still succeeds.Benchmark against Apache main
I measured the branch at 05ac57e6f independently. The baseline was Apache Comet main at ef771f2b. Both builds used stock Spark 4.0.4, Java 17.0.21.1, release native builds with jemalloc, native shuffle and AQE disabled. Each Spark application used
local[8]on Linux ARM64 with a 12 GiB driver heap and 4 GiB of Spark off-heap memory.Two jobs ran concurrently. Each ran both builds in separate JVMs, with the order reversed in the second job. Times include SQL planning through collecting all rows. Each time is the mean of the two job medians. Speedup divides the main time by the branch time. The last two columns show the ratios within each job. A negative saving means the branch took longer. These are single-host operator workloads. Shared host load and JVM variation can affect small differences.
For every measured execution the benchmark compared the schema and all result rows, including duplicates and nulls, with the same SQL on Spark with Comet disabled. All comparisons passed. Result digests also matched across builds and jobs. Verification, input preparation, Spark reference queries and warmups were outside the timer.
Each job ran one warmup and five timed collections per build and case. Input rows count the build side. The probe returned all 4,096 matching rows.
Both large joins used four ordered groups on the branch. The exchange received 3,072 batches of 2,048 rows. Mean median exchange
buildTimefell from 401.5 to 97.5 ms for ordered input and from 389.0 to 87.5 ms for nullable input. That time is already included in the table. The small control stayed serial and took 0.5 ms longer on average.Reproduce the measurements
Use the two Spark 4.0 assembly jars with the matching native libraries packaged for your platform. Set
MAIN_JARandPATCH_JARto their absolute paths. Save the Python below asbench.py. Start each invocation with a clean Spark configuration. Repeat with the order reversed in a second job. The script sets the relevant SQL options and asserts the executed paths.AI assistance
OpenAI Codex assisted with the implementation, tests, benchmarks and write-up.