avoid latency/copy when sending low-priority messages to fast peers (#1060)
This commit is contained in:
parent
aef44ed1ce
commit
84659af45b
|
@ -339,14 +339,21 @@ proc sendEncoded*(p: PubSubPeer, msg: seq[byte], isHighPriority: bool): Future[v
|
||||||
## priority messages have been sent.
|
## priority messages have been sent.
|
||||||
doAssert(not isNil(p), "pubsubpeer nil!")
|
doAssert(not isNil(p), "pubsubpeer nil!")
|
||||||
|
|
||||||
|
p.clearSendPriorityQueue()
|
||||||
|
|
||||||
|
# When queues are empty, skipping the non-priority queue for low priority
|
||||||
|
# messages reduces latency
|
||||||
|
let emptyQueues =
|
||||||
|
(p.rpcmessagequeue.sendPriorityQueue.len() +
|
||||||
|
p.rpcmessagequeue.nonPriorityQueue.len()) == 0
|
||||||
|
|
||||||
if msg.len <= 0:
|
if msg.len <= 0:
|
||||||
debug "empty message, skipping", p, msg = shortLog(msg)
|
debug "empty message, skipping", p, msg = shortLog(msg)
|
||||||
Future[void].completed()
|
Future[void].completed()
|
||||||
elif msg.len > p.maxMessageSize:
|
elif msg.len > p.maxMessageSize:
|
||||||
info "trying to send a msg too big for pubsub", maxSize=p.maxMessageSize, msgSize=msg.len
|
info "trying to send a msg too big for pubsub", maxSize=p.maxMessageSize, msgSize=msg.len
|
||||||
Future[void].completed()
|
Future[void].completed()
|
||||||
elif isHighPriority:
|
elif isHighPriority or emptyQueues:
|
||||||
p.clearSendPriorityQueue()
|
|
||||||
let f = p.sendMsg(msg)
|
let f = p.sendMsg(msg)
|
||||||
if not f.finished:
|
if not f.finished:
|
||||||
p.rpcmessagequeue.sendPriorityQueue.addLast(f)
|
p.rpcmessagequeue.sendPriorityQueue.addLast(f)
|
||||||
|
|
Loading…
Reference in New Issue