-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
always try to read ahead by at least 5 blocks in the PBDagReader #5162
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
12719a7
use `copy` instead of looping
Stebalien 0344e3e
better handle context cancellations in the PBDagReader
Stebalien ff3efb5
always prefetch at least 5 blocks ahead
Stebalien 5c0dc6a
test dag reader context cancellation
Stebalien 7fd3404
explain when a promise can be canceled in pbdagreader
Stebalien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
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.
(Apologies in advanced for the noise if I'm misunderstanding what this code does.)
So, if I'm understanding this correctly, right now the number of preloaded nodes available in advance goes like 10, 9, 8, ..., 0, all of a sudden the algorithm realizes it's out of nodes and has to load 10 more, causing the stuttering.
In that case, could we just move the
for
logic insidepreload
, calling it here every time without checking ifpromises[dr.linkPosition]
isnil
, so as to say: "I've consumed one node, heypreload()
, make sure I still havepreloadSize
nodes available in front of me, you figure out what to do".Maybe
preload
wouldn't even need thefor
, in the first call,dr.promises[0] == nil
, loadpreloadSize
nodes altogether, and after that, every time it's called (because a node has been consumed), preload the nodedr.promises[dr.linkPosition + preloadSize]
(assuming here that every node beforedr.linkPosition + preloadSize
is already loaded).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.
I've just realized that all the time I was talking about nodes I should have been talking about node promises, I can't know if there's a node until I call
Get()
right?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.
Sounds reasonable.
Technically, you can seek around so I'd rather be robust (the check is cheap).
No, but you can know if we've made a request for the node (i.e., the promise exists).
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.
Actually, it looks like making that change makes the other call to preload trickier. That second call currently overwrites any existing promises assuming that if the first preload has been canceled, the later ones probably have been as well.
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.
Note that fetching multiple blocks at once is more efficient.
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.
Oh, so maybe another constant N should be added that would indicate to call preload only if there are less than N available promises, to avoid calling it every time a node is consumed, e.g., if N is 5 then the number of available promises in advance would go like 10, 9, ..., 5, only now call preload, 15, 14, ..., 5, call preload again, etc.
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.
Maybe
preload()
could be extended to also check if the context ofdr.promises[i]
has been cancelled, not only that it'snil
. (Another argument could be added topreload()
to indicate if we want to overwrite the promises, but the other solution sound more correct to me.)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.
That's what I currently do. If we have fewer than half
preloadSize
loaded, I load the nextpreloadSize
. That means we vary between 5 and 15.That's what the TODO is about. However, that requires a change to the promises. See: ipfs/go-ipld-format#34
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.
I see, thanks for the clarification, then maybe we could add that extra argument to indicate that the current promises are cancelled and
preload
should request them again (overwriting the previous ones), if you think it's worth it.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.
I could but that doesn't seem any better to me. It just moves code from one place to another and then puts it behind a condition. Once we merge that linked PR, definitely.