feat: Add batch spill limit to improve shuffle writer throughput [experimental]#3941
Draft
andygrove wants to merge 4 commits intoapache:mainfrom
Draft
feat: Add batch spill limit to improve shuffle writer throughput [experimental]#3941andygrove wants to merge 4 commits intoapache:mainfrom
andygrove wants to merge 4 commits intoapache:mainfrom
Conversation
… writer The buffered shuffle writer accumulates all input batches in memory before writing partitioned output. With unlimited or large memory pools, this leads to poor cache locality during the final interleave phase, causing throughput to drop as more memory is available. Add a configurable batch_spill_limit that triggers spilling after a fixed number of buffered batches, regardless of memory availability. This keeps the working set bounded and maintains good cache locality. Config: spark.comet.exec.shuffle.batchSpillLimit (default: 100, 0=disabled) Benchmark (200 partitions, 100M rows, unlimited memory): - Without limit: 1.38 M rows/s, 22.6 GiB peak RSS - With limit=100: 2.43 M rows/s, 1.7 GiB peak RSS (+76% throughput, -93% memory)
andygrove
commented
Apr 14, 2026
| The batch spill limit is configured via `spark.comet.exec.shuffle.batchSpillLimit` (default: 100). Setting it | ||
| to 0 disables this threshold, meaning spills only occur under memory pressure. | ||
|
|
||
| In most cases, the default value of 100 provides good performance. If you observe that shuffle throughput |
Member
Author
There was a problem hiding this comment.
I will update this section once I have run benchmarks with different values
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?
Closes #.
Rationale for this change
The buffered shuffle writer (
MultiPartitionShuffleRepartitioner) accumulates all input batches in memory before writing partitioned output duringshuffle_write. When given ample memory (or no memory limit), it buffers everything — which paradoxically degrades throughput becauseinterleave_record_batchhas poor cache locality when working over a huge buffer of batches.Benchmarks show throughput drops as more memory is available:
What changes are included in this PR?
A new config
spark.comet.exec.shuffle.batchSpillLimit(default: 100) that triggers spilling after a fixed number of buffered input batches, regardless of memory availability. This keeps the working set bounded and maintains good cache locality during the interleave phase.The change is minimal — a single condition added to
buffer_partitioned_batch_may_spill:Setting
batchSpillLimit=0disables the threshold, preserving the existing behavior.Benchmark results (200 partitions, 100M rows, unlimited memory):
+76% throughput, -93% memory usage. No regression when memory is already constrained.
How are these changes tested?