HDDS-16323. StreamBlockInputStream: refill the pre-read window in bulk instead of once per response - #11159
Open
ss77892 wants to merge 2 commits into
Open
HDDS-16323. StreamBlockInputStream: refill the pre-read window in bulk instead of once per response#11159ss77892 wants to merge 2 commits into
ss77892 wants to merge 2 commits into
Conversation
chihsuan
approved these changes
Aug 30, 2026
| final long preReadLength = preRead ? preReadSize : 0; | ||
| // Refill the pre-read window in bulk once it drains below half, instead of after every response. | ||
| // Safe to skip: required <= 0 means the DataNode still owes bytes that poll() is waiting for. | ||
| if (required <= 0 && requestedLength - position >= preReadLength / 2) { |
Contributor
There was a problem hiding this comment.
nit: Just a thought, what do you think about giving the / 2 a name? A named constant might make the half-window trigger easier to spot later.
Contributor
Author
There was a problem hiding this comment.
Sure. I've added preReadRefillThreshold that is computed alongside preReadSize, so the test can reference the same value rather than repeating the / 2.
chungen0126
self-requested a review
August 31, 2026 09:50
…k instead of once per response
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.
What changes were proposed in this pull request?
StreamBlockInputStream: refill the pre-read window in bulk instead of once per response
This change adds an early return in readBlock(): when the caller's read is already covered by what has been requested (required <= 0) and the outstanding pre-read window is still at least half full, no new request is sent. The window is refilled in bulk only once it drains below half. When required > 0 the request is always sent, so a read that needs bytes beyond the requested range is never starved.
A unit test (testPreReadWindowIsRefilledInBulk) reads a block one response at a time, as KeyInputStream does, and checks that the number of ReadBlock requests is bounded by the number of half windows and that every request carries at least half a window.
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-16323
How was this patch tested?
UT added/ CI
Performance evaluation on 3 node cluster.
HDDS-16323.pdf