Skip to content
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

When priority is equal, use FIFO #16

Merged
merged 3 commits into from
Aug 24, 2021
Merged

Conversation

hannahhoward
Copy link
Collaborator

@hannahhoward hannahhoward commented Aug 24, 2021

Goals

I had been assuming in a peer task queue, if I queue tasks for a given peer with equal priority over time, that they will dequeue in FIFO order. As it turns out, this is not the case. This makes me super concerned -- we use this in Graphsync and it's a major bummer if requests don't queue in the order received for a given peer. Not sure the Bitswap implications but I can't imagine they are great.

Implementation

  • Change the PriorityCompare function
  • Add clock module to simulate time in test
  • Write peer tracker test to verify functionality (note this FAILS without the change to PriorityCompare)

For Discussion

Alternative idea would be to allow custom specification of priority order.

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

(one small change but the logic looks good)

@@ -59,14 +60,15 @@ type PeerTracker struct {
}

// New creates a new PeerTracker
func New(target peer.ID, taskMerger TaskMerger, maxActiveWorkPerPeer int) *PeerTracker {
func New(target peer.ID, taskMerger TaskMerger, maxActiveWorkPerPeer int, clock clock.Clock) *PeerTracker {
Copy link
Member

Choose a reason for hiding this comment

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

Given that this clock is just for testing... can we use a private global one? Otherwise, it becomes a part of the API.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yea fair I think.

Comment on lines 579 to 581
defer func() {
clockInstance = oldClock
}()
Copy link
Member

Choose a reason for hiding this comment

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

nit: use t.Cleanup to make sure this always runs.

@hannahhoward hannahhoward merged commit 2d21b37 into master Aug 24, 2021
@raulk raulk deleted the feat/fifo-equal-priority branch August 25, 2021 10:03
@aschmahmann aschmahmann mentioned this pull request Dec 1, 2021
80 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants