Skip to content

Add Queue Factory function to support injecting router schedulers#6262

Merged
tychoish merged 7 commits intobez/p2p-revise-queue-scheduler-pqfrom
tycho/p2p-revise-queue
Mar 22, 2021
Merged

Add Queue Factory function to support injecting router schedulers#6262
tychoish merged 7 commits intobez/p2p-revise-queue-scheduler-pqfrom
tycho/p2p-revise-queue

Conversation

@tychoish
Copy link
Contributor

This just centralizes how we construct queue instances and avoids using the fifo queue for ingestion and a different queue for outgoing messages.

It presently defaults to FIFO unless its explicitly overridden, but we may want to use the priority algorithm.

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Looks great @tychoish :)

peerMtx sync.RWMutex
peerQueues map[NodeID]queue // outbound messages per peer for all channels
queueFactory func(int) queue
queueBufferDefault int
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to have this be part of the type instead of just a private constant?

p2p/router.go Outdated
queue := newPQScheduler(r.logger, peerID, r.metrics, r.chDescs, 0, 0, defaultCapacity)
queue.start()
var peerQueue queue
func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why put this into a function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to be able to use the defer on the unlock.

Copy link
Contributor

Choose a reason for hiding this comment

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

we can avoid the defer by calling r.peerMtx.Unlock() directly after the code block. Note a blocker, I just find inline functions a bit harder to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this into it's own function, which I think improves readability. Given that the changes means that we have to call a function in the lock, I'm a bit afraid of doing that without a defer, as a matter of practice.

@tychoish tychoish merged commit a4243d0 into bez/p2p-revise-queue-scheduler-pq Mar 22, 2021
@tychoish tychoish deleted the tycho/p2p-revise-queue branch March 22, 2021 19:17
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.

2 participants