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

Bitswap Refactor #4: Extract session peer manager from sessions #26

Merged
merged 7 commits into from
Dec 17, 2018

Conversation

hannahhoward
Copy link
Contributor

@hannahhoward hannahhoward commented Nov 16, 2018

Goals

Modularize Bitswap in preparation for attempts to optimize bitswap further

This also gets us quite a bit of the way toward the proposed split of bitswap into low level "just ask for blocks from peers and respond to requests" bitswap and high level bitswap -- sessions, and possibly other drivers as time goes on.

Implementation

Final PR includes:

  • Extracted out the managing of peers for a session into it's own backage -- this way, tracking optimal peers is seperate from improving algorithms for fetch blocks
  • Commented all exported functions to
  • Unit test new session manager, new session peermanager
  • Unit test sessions (they are currently really more integration tested in the main package)

For discussion

child of ipfs/kubo#5723

@ghost ghost assigned hannahhoward Nov 16, 2018
@ghost ghost added the status/in-progress In progress label Nov 16, 2018
Copy link

@lanzafame lanzafame left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand a fair amount of this is just shuffling code around but I figure if it's being moved around it can get freshened up as well.

On top of the comments made, could all the exported types and functions/methods get a godoc comment, please?

sessionmanager/sessionmanager.go Outdated Show resolved Hide resolved
sessionmanager/sessionmanager.go Show resolved Hide resolved
sessionmanager/sessionmanager.go Outdated Show resolved Hide resolved
sessionmanager/sessionmanager.go Outdated Show resolved Hide resolved
sessionmanager/sessionmanager.go Outdated Show resolved Hide resolved
messagequeue/messagequeue.go Outdated Show resolved Hide resolved
messagequeue/messagequeue.go Outdated Show resolved Hide resolved
func (mq *msgQueue) openSender(ctx context.Context) error {
// allow ten minutes for connections this includes looking them up in the
// dht dialing them, and handshaking
conctx, cancel := context.WithTimeout(ctx, time.Minute*10)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timeout value could potentially be a configuration field of the msgQueue struct? Not sure though

return mq.refcnt > 0
}

func (mq *msgQueue) AddMessage(entries []*bsmsg.Entry, ses uint64) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ses?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

session id. I don't make the variable names, I just copy-paste them. :)
But good point and I'll work on some variable names too -- just one at a time.

bitswap.go Outdated Show resolved Hide resolved
wantmanager/wantmanager.go Outdated Show resolved Hide resolved
messagequeue/messagequeue.go Outdated Show resolved Hide resolved
sessionmanager/sessionmanager.go Outdated Show resolved Hide resolved
@hannahhoward hannahhoward force-pushed the feat/refactor-sessions branch 2 times, most recently from 90995eb to a616ddb Compare November 28, 2018 23:30
@hannahhoward hannahhoward changed the title WIP: Bitswap Refactor For Cleanliness Bitswap Refactor For Cleanliness Nov 29, 2018
@hannahhoward hannahhoward force-pushed the feat/refactor-sessions branch 7 times, most recently from 744f9e4 to b6787e8 Compare December 1, 2018 02:40
@hannahhoward
Copy link
Contributor Author

@lanzafame @whyrusleeping @michaelavila @eingenito @djdv I believe this PR to be done and would love any feedback you have. FYI, much has changed since the last round of feedback.

Seeking 2 solid LGTMs before merge.

@parkan
Copy link

parkan commented Dec 3, 2018

we've been hearing a bunch of feedback about bitswap performance from folks using ipfs in production, would love to see this merged so performance work can happen on top of it!

@whyrusleeping
Copy link
Member

This PR is exceedingly large, which makes review quite difficult. I would not feel comfortable pushing this through without proper review (especially since there are structural changes to core components)

@Stebalien Stebalien requested a review from djdv December 3, 2018 19:18
@Stebalien
Copy link
Member

@djdv I've assigned you to review this as you're also working on bitswap performance. However, if you're swamped, we can find someone else.

@hannahhoward
Copy link
Contributor Author

@whyrusleeping

I appreciate the feedback about the size of the PR. That's fair

I will write up an explanation tomorrow of some design decisions and also do some line by line commenting.

I can also do a video screencast to go over it.

To be clear, while there are a number of changes, my belief is there is only one potential "breaking change" (SessionsForBlock was technically a public bitswap method, even though it's not actually used publicly as far as I know, certainly not in go-ipfs), and only a few changes that go beyond moving code around and restructuring.

@whyrusleeping
Copy link
Member

@hannahhoward I think this would be much easier if it were many smaller PRs. Each of the individual changes made here could be PRed as they happen, giant sweeping 'refactor' PRs are a great way for bugs to sneak in, especially when the author insists they are 'just moving stuff around'.

For example, the previous Run method has been broken up into smaller pieces, and at the same time, moved to a different file. Reviewing this is quite a bit more time consuming now, as I have to pull up the old code in a separate window, and manually diff it against the newly changed stuff. It seems fine, but it would have been nice to see a simple file rename, and then the changes happen separately.

@hannahhoward
Copy link
Contributor Author

@whyrusleeping it's actually not to late to seperate into separate PRs, and I think that's a reasonable idea. The commit history is fairly linear and most commits have passing tests, so I think that's a reasonable change.

@whyrusleeping
Copy link
Member

@hannahhoward awesome!

@hannahhoward
Copy link
Contributor Author

@djdv @whyrusleeping @Stebalien @lanzafame @eingenito @michaelavila

I get it -- 20+ fully modified files is a lot to digest, and hard to follow the progress and thinking of.

I've seperated this into 4 seperate PRs. The first I am hoping we can merge fairly quickly, as it only covers what several people have already commented on (plus some fixes for those comments, and the remaining issues are addressed in subsequent PRs):
#28

The next is the seperate of the want manager and peer manager, plus unit tests and further cleanup:
#29

The 3rd is just extracting sessions to a package:
#30

And finally there this PR, which is now just extracting the session peer manager from sessions itself, plus remaining unit tests.

I've set the base of the PR for each branch to the previous branch, and will change the base to master as we merge.

@parkan parkan changed the title Bitswap Refactor For Cleanliness Bitswap Refactor #4: Extract session manager from sessions Dec 5, 2018
@parkan parkan changed the title Bitswap Refactor #4: Extract session manager from sessions Bitswap Refactor #4: Extract session peer manager from sessions Dec 5, 2018
@parkan
Copy link

parkan commented Dec 5, 2018

took the liberty to rename this PR for consistency and clarity

thank you for putting in the work to make these changes easier to review 💯

extract the job of finding and managing peers for a session from the job of requesting blocks
Add a unit test and do some additional decoupling
Add unit test for sessionpeermanger and comment exported methods
Add a unit test for session package
@hannahhoward hannahhoward changed the base branch from feat/extract-sessions to master December 13, 2018 18:56
@hannahhoward
Copy link
Contributor Author

@Stebalien @whyrusleeping @lanzafame @eingenito @michaelavila I know you all already took a look at this one when it was a giant blob, but it's ready to review on it's own as the final PR in this refactor sequence.

Copy link

@eingenito eingenito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore my comments - they were existing code and no need to change.

out := cq.elems[0]
cq.elems = cq.elems[1:]

if cq.eset.Has(out) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't really matter - but I think Remove no-ops if the target doesn't exist - so might not need the Has call. Totally not something that has to be changed.

}

func (cq *cidQueue) Len() int {
return cq.eset.Len()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also totally doesn't matter but you'll Pop() if something is in the set or not - maybe you should take the length of elems?

@hannahhoward
Copy link
Contributor Author

Merging on account of it's been open several days and @eingenito reviewing in depth

@hannahhoward hannahhoward merged commit 4fc6272 into master Dec 17, 2018
@ghost ghost removed the status/in-progress In progress label Dec 17, 2018
Jorropo pushed a commit to Jorropo/go-libipfs that referenced this pull request Jan 26, 2023
Bitswap Refactor ipfs#4: Extract session peer manager from sessions

This commit was moved from ipfs/go-bitswap@4fc6272
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.

6 participants