-
Notifications
You must be signed in to change notification settings - Fork 55
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
make relayed messages non priority #1009
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## unstable #1009 +/- ##
============================================
+ Coverage 83.13% 83.22% +0.09%
============================================
Files 91 91
Lines 15344 15419 +75
============================================
+ Hits 12756 12833 +77
+ Misses 2588 2586 -2
|
65e5c01
to
80baf71
Compare
|
||
await conn.close() # This will clean up the send connection | ||
if isHighPriority: | ||
await p.rpcmessagequeue.priorityQueue.put(msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in general, the queue for priority messages is not needed - one can simply send the message and put its future on a deque
to achieve the same effect.
For non-priority messages, these are put on a queue like in this PR. The "worker loop" for non-priority messages then becomes:
sendQueue: var Deque[Future[void]]
proc clearSendQueue() =
while sendQueue.len > 0 and senQueue[0].finished:
discard sendQueue.popFirst()
proc addSendQueue(msg: Future[void]) =
clearSendQueue()
if not msg.finished: sendQueue.addLast(msg)
proc send(msg): Future[void] = ...
while true:
let msg = await nonPrioQueue.popFirst()
while sendQueue.len > 0:
await sendQueue[^1]
clearSendQueue()
addSendQueue(send(msg))
Among other things, this avoids latency for publishing prio message as well as the additional memory traffic resulting from message copies.
I'm also not sure what messageAvailable
is doing here - await nonPriorityQueue.popFirst()
already wakes up whenever there's a message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the priority queue is for the case when we're trying to publish messages faster than we can send them. In this case we'll need to either drop or slow down somehow. How are we going to achieve the same without an explicit queue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this avoids latency for publishing prio message
Could you please elaborate more on how the current code causes this latency? Currently, we don't send a non-priority message as long as there's a priority message to be sent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the priority queue is for the case when we're trying to publish messages faster than we can send them. In this case we'll need to either drop or slow down somehow. How are we going to achieve the same without an explicit queue?
There is still a queue, but it is implicit: it exists in the form of pending futures - similar to how it happens now - asyncSpawn
puts things in a hidden implicit queue
Pending futures can be cancelled - ie the deque
I suggest above does exactly that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please elaborate more on how the current code causes this latency? Currently, we don't send a non-priority message as long as there's a priority message to be sent.
In this PR, you copy the message into priorityQueue
which wakes up processMessages
which removes the message from the priorityQueue
and adds it to the (hidden) send queue of the connection - the time it takes to wake up processMessages
is added latency (and additional copies of the message) - it is at least one iteration of the event poll loop which can take several milliseconds (or worse, if there's a lot of work).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, thanks for the explanation. How will the new proposed solution prioritize the published msgs over the relayed ones? Will we check the sendQueue for priority messages and send non-priority ones only when this queue is empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that's how it could work - not added in my snippet is that priority messages also get tracked via sendQueue
5ff07ff
to
c70f88f
Compare
c70f88f
to
9eb9cca
Compare
This has been replaced by #1015 |
This PR is still in an exploratory phase and the base idea is to give a lower priority to the messages received from other peers that need to be relayed than the messages published by the peer.