Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

fix: reduce receive contention #536

Merged
merged 1 commit into from
Oct 26, 2021
Merged

fix: reduce receive contention #536

merged 1 commit into from
Oct 26, 2021

Conversation

Stebalien
Copy link
Member

This means we need to frequently re-take this lock, but it also means we don't hold it while calling other functions that might block (e.g., while pushing jobs).

This means we need to frequently re-take this lock, but it also means we
don't hold it while calling other functions that might block (e.g.,
while pushing jobs).
Comment on lines +679 to +681
e.lock.RLock()
peers := e.peerLedger.Peers(k)
e.lock.RUnlock()
Copy link
Contributor

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?

Copy link
Member Author

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.

Comment on lines +684 to +686
e.lock.RLock()
ledger, ok := e.ledgerMap[p]
e.lock.RUnlock()
Copy link
Contributor

@aschmahmann aschmahmann Oct 22, 2021

Choose a reason for hiding this comment

The 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)?

Copy link
Member Author

Choose a reason for hiding this comment

The 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).

@whyrusleeping
Copy link
Member

This is working well for me, except now im hitting other issues that I think the lock contention was holding back

@Stebalien Stebalien merged commit 1ab28b8 into master Oct 26, 2021
@Stebalien Stebalien deleted the fix/receive-contention branch October 26, 2021 06:14
@aschmahmann aschmahmann mentioned this pull request Dec 1, 2021
80 tasks
Jorropo pushed a commit to Jorropo/go-libipfs that referenced this pull request Jan 26, 2023
fix: reduce receive contention

This commit was moved from ipfs/go-bitswap@1ab28b8
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants