Repository navigation
perf(shuffle): reduce pool contention - #26160
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Blocking review finding (GitHub does not allow this account to request changes on its own PR): The per-bucket recycle cache can be permanently starved by an inactive bucket.
The old global pool reused those buffers across buckets. There is no in-generation eviction, quota, or steal path that breaks the new cycle. This is reachable for range/sorted or otherwise phase-skewed shuffle inputs and directly contradicts this performance PR's goal. Please preserve the global bound while preventing one inactive bucket from monopolizing it—for example with bounded cross-bucket stealing or a fair per-bucket reservation—and add a deterministic phase-skew regression that fills one bucket's cache and then proves another bucket reuses rather than repeatedly allocates/discards. The current cache-bound and concurrent accounting tests set every batch's default I otherwise traced the pool lifecycle and found no additional blocker: holder finalization excludes concurrent cleanup, producer shutdown is joined before release, ready batches and recycle storage remain bounded, error-path ownership is preserved, and incremental accounting covers the mutable tail plus appended batches. Fresh local full shuffle |
|
Fixed the blocking cross-bucket recycle starvation in The cache still prefers the current bucket, but on a local miss it now performs a bounded scan and uses Added a deterministic production-path regression that fills bucket 0 to the global recycle limit, writes to bucket 1, and proves that bucket 1 receives one of bucket 0s cached batches. The test failed at the previous head Benchmark on Apple M4 (
Fresh validation after the final edit:
|
|
Blocking re-review finding (this account still cannot submit Request Changes on its own PR): the recycle-cache fix is performance-overfit to the 2-bucket case. The 2-bucket regression is valid, but I reproduced this with overlay-only benchmarks against the same code paths, without modifying the PR tree. Apple M4, 100000x, 5 runs:
At 1024 buckets the current round-robin pool path is 1.78-1.81 us/op versus about 18 ns/op on the original global pool. The current code removes the allocation loop from Recommendation: keep |
|
Resolved the blocking re-review in The final recycle design uses Apple M4, 1,000,000 iterations, 5 runs, all final cases at 0 B/op and 0 allocs/op:
The committed matrix also includes the 1024-bucket full Added deterministic coverage for single-CN, multi-CN, drain-all, every-bucket reuse, cold-shard warmup, concurrent two-workers-per-shard reuse, total worker-bound capacity, memory-accounting shards, and allocation-error ownership. Final Q1-Q3 audit:
Fresh final validation passed: focused |
|
做了一轮 correctness / robustness / unhappy-path review,这版我没看到新的问题。重点看了 4 件事:\n\n1. |
|
重新按当前 head 做了一轮 correctness / robustness / unhappy-path 复核,结论没变:当前这版我没有看到新的高置信 blocker。 重点又过了一遍这几条链:
包级 因为这是你的 PR,GitHub 不允许我直接 self-approve,所以这里继续用 comment 代替:当前看还是 LGTM。 |
## What type of PR is this? - [x] Improvement ## What this PR does / why we need it Reduce contention in the shared shuffle pool without changing shuffle backpressure or buffering limits: - account only batches changed by each union instead of rescanning the whole bucket - shard batch memory tracking to remove the global accounting mutex - shard recycled batches by the local holder bound, with two padded embedded slots per shard - keep recycle lookup O(1) independently of the global shuffle bucket count - let a cold holder shard warm once without allowing a previously hot bucket to monopolize the cache The recycle capacity remains exactly `2 * maxHolders`. Sharding follows the local concurrency bound rather than `bucketNum`, which can grow as stage nodes times DOP in multi-CN plans. This is complementary to the allocator/mmap work in matrixorigin#26143 and is kept separate so both changes can be reviewed, measured, and reverted independently. Related to matrixorigin#26132. Follow-up to matrixorigin#26143. ## Which issue(s) this PR fixes None. matrixorigin#26143 already owns the closing reference for matrixorigin#26132. ## Testing - focused recycle/accounting/error-path stress under `-race -count=50` - `go test -race ./pkg/sql/colexec/shuffle` - `go test ./pkg/sql/colexec/shuffle ./pkg/sql/compile ./pkg/vm/pipeline ./pkg/vm` - `go test -race ./pkg/vm/pipeline` - `go build ./pkg/sql/colexec/shuffle` - `go vet ./pkg/sql/colexec/shuffle` - benchmark matrix covering 16/128/1024 buckets, fixed-worker concurrency, single-CN, multi-CN, drain-all, round-robin, and phased skew
## What type of PR is this? - [x] Improvement ## What this PR does / why we need it Reduce contention in the shared shuffle pool without changing shuffle backpressure or buffering limits: - account only batches changed by each union instead of rescanning the whole bucket - shard batch memory tracking to remove the global accounting mutex - shard recycled batches by the local holder bound, with two padded embedded slots per shard - keep recycle lookup O(1) independently of the global shuffle bucket count - let a cold holder shard warm once without allowing a previously hot bucket to monopolize the cache The recycle capacity remains exactly `2 * maxHolders`. Sharding follows the local concurrency bound rather than `bucketNum`, which can grow as stage nodes times DOP in multi-CN plans. This is complementary to the allocator/mmap work in matrixorigin#26143 and is kept separate so both changes can be reviewed, measured, and reverted independently. Related to matrixorigin#26132. Follow-up to matrixorigin#26143. ## Which issue(s) this PR fixes None. matrixorigin#26143 already owns the closing reference for matrixorigin#26132. ## Testing - focused recycle/accounting/error-path stress under `-race -count=50` - `go test -race ./pkg/sql/colexec/shuffle` - `go test ./pkg/sql/colexec/shuffle ./pkg/sql/compile ./pkg/vm/pipeline ./pkg/vm` - `go test -race ./pkg/vm/pipeline` - `go build ./pkg/sql/colexec/shuffle` - `go vet ./pkg/sql/colexec/shuffle` - benchmark matrix covering 16/128/1024 buckets, fixed-worker concurrency, single-CN, multi-CN, drain-all, round-robin, and phased skew
## What type of PR is this? - [x] Improvement ## What this PR does / why we need it Reduce contention in the shared shuffle pool without changing shuffle backpressure or buffering limits: - account only batches changed by each union instead of rescanning the whole bucket - shard batch memory tracking to remove the global accounting mutex - shard recycled batches by the local holder bound, with two padded embedded slots per shard - keep recycle lookup O(1) independently of the global shuffle bucket count - let a cold holder shard warm once without allowing a previously hot bucket to monopolize the cache The recycle capacity remains exactly `2 * maxHolders`. Sharding follows the local concurrency bound rather than `bucketNum`, which can grow as stage nodes times DOP in multi-CN plans. This is complementary to the allocator/mmap work in matrixorigin#26143 and is kept separate so both changes can be reviewed, measured, and reverted independently. Related to matrixorigin#26132. Follow-up to matrixorigin#26143. ## Which issue(s) this PR fixes None. matrixorigin#26143 already owns the closing reference for matrixorigin#26132. ## Testing - focused recycle/accounting/error-path stress under `-race -count=50` - `go test -race ./pkg/sql/colexec/shuffle` - `go test ./pkg/sql/colexec/shuffle ./pkg/sql/compile ./pkg/vm/pipeline ./pkg/vm` - `go test -race ./pkg/vm/pipeline` - `go build ./pkg/sql/colexec/shuffle` - `go vet ./pkg/sql/colexec/shuffle` - benchmark matrix covering 16/128/1024 buckets, fixed-worker concurrency, single-CN, multi-CN, drain-all, round-robin, and phased skew
What type of PR is this?
What this PR does / why we need it
Reduce contention in the shared shuffle pool without changing shuffle backpressure or buffering limits:
The recycle capacity remains exactly
2 * maxHolders. Sharding follows the local concurrency bound rather thanbucketNum, which can grow as stage nodes times DOP in multi-CN plans.This is complementary to the allocator/mmap work in #26143 and is kept separate so both changes can be reviewed, measured, and reverted independently.
Related to #26132.
Follow-up to #26143.
Which issue(s) this PR fixes
None. #26143 already owns the closing reference for #26132.
Testing
-race -count=50go test -race ./pkg/sql/colexec/shufflego test ./pkg/sql/colexec/shuffle ./pkg/sql/compile ./pkg/vm/pipeline ./pkg/vmgo test -race ./pkg/vm/pipelinego build ./pkg/sql/colexec/shufflego vet ./pkg/sql/colexec/shuffle