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

Extend peer task queue to work with want-have / want-block #8

Merged
merged 19 commits into from Nov 11, 2019

Conversation

dirkmc
Copy link
Contributor

@dirkmc dirkmc commented Oct 28, 2019

The Bitswap proof-of-concept

  • supports new message types
  • pushes requests onto the request queue individually (instead of in groups)
  • pulls requests off the request queue by size (instead of in pre-pushed groups)

This PR extends peer task queue to support Bitswap's requirements and

  • orders peers by outstanding bytes (rather than number of blocks)

See ipfs/go-bitswap#197

@dirkmc dirkmc requested a review from Stebalien October 28, 2019 21:40
peertask/peertask.go Outdated Show resolved Hide resolved
peertask/peertask.go Show resolved Hide resolved
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.

LGTM. The only things that really need to be fixed are the documentation issues.

Otherwise, I'd like to give @hannahhoward a chance to review.

peertask/peertask.go Outdated Show resolved Hide resolved
peertaskqueue.go Outdated Show resolved Hide resolved
peertracker/peertracker.go Outdated Show resolved Hide resolved
peertracker/peertracker.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@hannahhoward hannahhoward left a comment

Choose a reason for hiding this comment

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

Approve on the condition yall do the Graphsync update -- which I don't think will be too hard.

I am curious how this will affect allocations... I believe that part of the point of the old architecture was essentially to avoid every reallocating task blocks or changing the list order... hence the someone odd tactic of marking task blocks as garbage rather than removing them from the queue, until they got to the front. That always felt like possibly premature optimization but I don't know the history -- @Stebalien might.

@Stebalien
Copy link
Member

hence the someone odd tactic of marking task blocks as garbage rather than removing them from the queue, until they got to the front.

So:

  1. Queuing multiple tasks at once was actually added pretty recently (well after the task deletion logic). I believe we chose to group tasks on push instead of pop because it was convenient (I think?).
  2. In terms of marking tasks as deleted versus removing them up-front, I'm not sure what the logic was. Any operation on the queue will be O(log(len(queue))). Really, the sooner we remove elements, the smaller the queue stays and the less work we do.

So yeah, probably premature (and possibly incorrect) optimization.

@dirkmc
Copy link
Contributor Author

dirkmc commented Nov 1, 2019

go-ipfs-pq has this cryptic comment:

	// TODO  explain why this interface should not be extended
	// It does not support Remove. This is because...

My assumption was that it doesn't support Remove() because removing from a heap is not as efficient as popping from the head of the heap (the heap is optimized to pop the head). Therefore it's more efficient to simply mark as removed and discard once it gets to the head. Just a guess though.

Perhaps we should add a Removed flag to the Task, and the heap sort function should move removed tasks to the front of the queue so that they are popped first (to be able to GC as soon as possible).

@Stebalien
Copy link
Member

My assumption was that it doesn't support Remove() because removing from a heap is not as efficient as popping from the head of the heap (the heap is optimized to pop the head). Therefore it's more efficient to simply mark as removed and discard once it gets to the head. Just a guess though.

I seem to recall asking Why about this and he couldn't remember. As far as I know, Remove and Pop are both O(log(n)) so it shouldn't matter. (see point two in my previous comment)

@Stebalien
Copy link
Member

Ah, I guess remove may have to do ~2log(n) operations (in practice)? It still seems worth it to remove items as fast as we can instead so n doesn't grow.

@dirkmc
Copy link
Contributor Author

dirkmc commented Nov 1, 2019

Looking at the source code that is correct, Remove may do twice as many operations, depending on where in the heap the removed item is.

In any case I agree that overall it's going to be either a negligible difference or maybe even net-positive to have Remove(). I'll add a PR against go-ipfs-pq.

@dirkmc
Copy link
Contributor Author

dirkmc commented Nov 1, 2019

ipfs/go-ipfs-pq#5

@dirkmc dirkmc requested a review from Stebalien November 1, 2019 16:19
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.

LGTM. Could you submit a PR against go-graphsync before we merge this?

@Stebalien
Copy link
Member

Well, LGTM except the tests are failing.

@dirkmc
Copy link
Contributor Author

dirkmc commented Nov 11, 2019

Created PR against go-graphsync: ipfs/go-graphsync#44

@Stebalien Stebalien merged commit f0529d7 into master Nov 11, 2019
@Stebalien Stebalien deleted the feat/proto-ext-poc branch November 11, 2019 22:34
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.

None yet

3 participants