This repository has been archived by the owner on Feb 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 112
fix: reduce receive contention #536
Merged
Merged
Changes from all commits
Commits
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -673,12 +673,18 @@ func (e *Engine) ReceiveFrom(from peer.ID, blks []blocks.Block) { | |
// Check each peer to see if it wants one of the blocks we received | ||
var work bool | ||
missingWants := make(map[peer.ID][]cid.Cid) | ||
e.lock.RLock() | ||
for _, b := range blks { | ||
k := b.Cid() | ||
|
||
for _, p := range e.peerLedger.Peers(k) { | ||
e.lock.RLock() | ||
peers := e.peerLedger.Peers(k) | ||
e.lock.RUnlock() | ||
|
||
for _, p := range peers { | ||
e.lock.RLock() | ||
ledger, ok := e.ledgerMap[p] | ||
e.lock.RUnlock() | ||
Comment on lines
+684
to
+686
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a sanity check question. Does it matter if the operations in the unlocked portion end up happening on an invalid ledger (i.e. one that is either no longer in the map)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kind of. But... that's already an issue pretty much everywhere in the code so I'm ignoring it for now. Really, we need to be reference counting, but that's a larger change. I say kind of because all this code is a bit racy (which is why we re-broadcast wants occasional). |
||
|
||
if !ok { | ||
// This can happen if the peer has disconnected while we're processing this list. | ||
log.Debugw("failed to find peer in ledger", "peer", p) | ||
|
@@ -718,7 +724,6 @@ func (e *Engine) ReceiveFrom(from peer.ID, blks []blocks.Block) { | |
e.updateMetrics() | ||
} | ||
} | ||
e.lock.RUnlock() | ||
|
||
// If we found missing wants (e.g., because the peer disconnected, we have some races here) | ||
// remove them from the list. Unfortunately, we still have to re-check because the user | ||
|
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.
Are you assuming that the amount of time to grab the ledger maps for all the peers is long enough that it's worth locking for each peer rather than grabbing all the ledgers at once and chucking them into an array?
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.
No, I'm just assuming that repeatedly taking and releasing the lock isn't going to be too expensive.