-
Couldn't load subscription status.
- Fork 3.6k
[opt](merge-io) Implement adaptive merge window sizing for MergeRangeFileReader to prevent read amplification #57303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
|
run buildall |
ClickBench: Total hot run time: 27.81 s |
| if (gap >= max_single_gap) { | ||
| break; | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gap >= max_single_gap meas gap >= SMALL_IO is always true
What problem does this PR solve?
Summary
Introduced adaptive logic to dynamically control merge window sizing in
MergeRangeFileReader, preventing severe read amplification in sparse data
scenarios while maintaining efficient merging for dense data patterns.
Problem
The original implementation used a fixed merge window (e.g., 8MB) which
worked well for dense columnar data but caused severe read amplification
with sparse ranges:
Example: Large Gap Scenario (3 ranges × 100KB with 600KB gaps)
Solution
Implemented a three-layer adaptive defense mechanism in read_at_impl():
Hard Gap Limit (max_single_gap = 512KB)
Immediately rejects merging if a single gap exceeds 512KB, preventing
catastrophic amplification from huge gaps.
Original Threshold (SMALL_IO = 2MB)
Stops merging when accumulated data > 2MB and next gap ≥ 2MB, maintaining
backward compatibility for typical use cases.
Predictive Gap Ratio Check (adaptive_shrink_threshold = 0.4)
Key Innovation: Proactively checks if including the next gap would push
the gap/content ratio above 40%. Stops merging BEFORE including problematic
gaps, not after.
Performance Results
Scenario 1: Sparse Gaps (15 ranges × 80KB with 50KB gaps)
Before (without adaptive logic):
After (with adaptive logic):
Scenario 2: Dense Gaps (10 ranges × 100KB with 5KB gaps)
Before & After (identical behavior):
Scenario 3: Large Gaps (3 ranges × 100KB with 600KB gaps)
Before (if original logic merged):
After (with max_single_gap=512KB):
Release note
None
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)