Repository navigation
Keep the stable task distribution of object storage files when replicas are balanced - #128433
Conversation
…istributor` Once the iterator was exhausted, a replica that asked for a task took a file of the replica with the most remaining bytes among the replicas that had already asked for tasks, immediately. These replicas keep asking until they receive an empty task, so their files would be processed anyway, and taking them only moved them to random replicas depending on the timing of the requests, breaking the cache locality of the rendezvous hashing. Now a replica first takes its own queued files, and takes the files of a replica that has asked for tasks only when that replica has more than twice the average remaining bytes of the other replicas. Otherwise it receives an empty task. The files of replicas that haven't asked yet are handled as before (`cluster_function_wait_for_replica_ms`), and the files of replicas that have received an empty task can always be taken. The decision doesn't wait, because the requests are served synchronously by the threads of the initiator, and waiting could block the requests of the replica whose files are waited for. #128403 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [60a7b83] Summary: ✅
AI ReviewSummaryThe PR aims to preserve object-storage cache locality by preferring each replica's queued files and limiting stealing from connected replicas to queues exceeding twice the other replicas' average remaining bytes. Review of head Findings
Tests
Final VerdictStatus: |
| if (!should_wait) | ||
| break; |
There was a problem hiding this comment.
[P2] Validate the cache benefit and latency cost of early completion
This now ends a replica's participation while other replicas still have queued files. The added unit tests prove the selection rule for a fixed queue snapshot, but do not establish the claimed performance improvement with real readers: remaining_bytes excludes files already handed out, and an idle replica that exits here cannot help if the remaining readers subsequently fall behind. The linked issue contains measurements only for the old implementation.
Please add a small before/after comparison of repeated queries over a fixed replica set, reporting filesystem-cache bytes, S3 bytes, and elapsed time. Include a skewed-file workload so the cache-locality gain is evaluated alongside the cost of retiring readers. A focused benchmark or measurements in the PR description would close this gap.
There was a problem hiding this comment.
🕵 Agreed that the unit tests only pin the selection rule, not the end-to-end effect. A meaningful before/after measurement needs a real multi-node cluster reading from S3 with a filesystem cache on each node (the effect depends on the request timing of the replicas, which a single-host setup with MinIO doesn't reproduce), and that is not available in this automated environment, so I am leaving this thread open for a human to provide numbers.
Notes on the two risks raised:
- Cache benefit: with the change, after the iterator is exhausted a file goes to a replica other than its rendezvous owner only when the owner has not asked for tasks within
cluster_function_wait_for_replica_ms, when the owner has already finished, or when the owner has more than twice the average remaining queued bytes of the other replicas. In the balanced case, the assignment is therefore the same in every query, which is what keeps the cache hits; the issue (Parallel replicas for object storage: work stealing breaks the cache locality of the stable task distribution #128403) shows 20-40% of bytes being re-read from S3 with the old timing-dependent assignment. - Latency cost of retiring readers: an idle replica stops only when no replica has more than 2x the average remaining queued bytes, so the worst-case extra tail is bounded by roughly the skew allowed by that threshold. You are right that
remaining_bytesdoes not include files already handed out, so a replica slowed down by one huge in-flight file is not detected. Skewed workloads where one file dominates are better handled by splitting the file into tasks (row groups / buckets) than by stealing whole files, which also breaks cache locality.
A benchmark with repeated queries over a fixed replica set (uniform and skewed file sizes, reporting CachedReadBufferReadFromCacheBytes, ReadBufferFromS3Bytes and elapsed time) would close this; I'll leave it to the author/reviewer to run it on a real cluster.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 21 s compile time in total, 8 of them have a recent master baseline. |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128433&sha=13a08d58c8964f2b59da12ec2f28b027c99b7780&name_0=PR&name_1=Performance%20Comparison%20%28amd_release%2C%20master_head%2C%205%2F6%29 ( |
|
This run had no performance reference build: job.log line 144, The fix is #128453, merged 2026-11-01 22:14Z, after this run (04:28Z). The current head |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128433&sha=31c76b92c4891b1691d1e5dce13e80ce01f960ea&name_0=PR&name_1=AST%20fuzzer%20%28amd_release%2C%20oracle%29 (TLP WHERE oracle mismatch for Thanks for the analysis of the earlier |
|
The fix is already in progress: #113332 (open, closes #106922; no updates since 2026-10-15). Not related to this PR. Cause: with a #113332 adds these exact queries on the same table to |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128433&sha=ef9d991fdb713d4a4d9102986f8f4dd5d8ed803f&name_0=PR&name_1=La%20Casa%20Del%20Dolor%20%28amd_tsan%29 ( I merged the latest master ( |
|
This run is from before #128774. The workflow started on 2026-11-03 at 08:44 UTC and #128774 was merged at 09:28 UTC, so the tested merge commit does not contain it: The CI agrees. Since #128774 was merged, La Casa Del Dolor |
|
🕵 Thanks, agreed: the tested merge commit predates #128774, and the current head The remaining open review thread asks for a before/after benchmark on a real multi-node cluster with per-node filesystem caches, which needs a human to run. |
With parallel replicas for object storage and
*Clustertable functions,StorageObjectStorageStableTaskDistributorassigns every file to a replica by rendezvous hashing, so that the same file is read by the same replica, and from its cache, in every query. But once the iterator was exhausted, a replica that asked for a task immediately took a file of the replica with the most remaining bytes, among the replicas that had already asked for tasks. Those replicas keep asking until they receive an empty task, so their files would be processed anyway. Taking them only moved them to random replicas depending on the timing of the requests. This was common with slow iterators like Iceberg's, where most replicas become idle and ask at the same moment, and repeated queries kept reading 20-40% of their bytes from S3 instead of the filesystem cache.Now, once the iterator is exhausted:
cluster_function_wait_for_replica_ms);This implements the second option from the issue. The first option would wait since the owner's last request. It isn't used because the read task requests are served synchronously by the initiator's pipeline threads. Many idle replicas waiting there could block the threads that serve the owner's own requests, and the owner's files would then be taken anyway.
Trade-off: if a replica fails in the middle of the query after it has asked for tasks, its queued files are no longer taken by others. The result in that case was already incomplete, because the files the replica was reading are lost.
Closes: #128403
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
With parallel replicas for object storage and
*Clustertable functions, an idle replica no longer takes the files assigned to another replica that is still processing its own files, unless that replica has much more work left than the others. This keeps the assignment of files to replicas stable across queries and improves the hit rate of the filesystem and page caches.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128433]
Version info
26.11.1.1559-master(included in26.11and later)