htlcswitch/link: conditional batch ticker
In this commit, we prevent the htlcManager from being woken up by the batchTicker when there is no work to be done. Profiling has shown a significant portion of CPU time idling, since the batch ticker endlessly demands resources. We resolve this by only selecting on the batch ticker when we have a non-empty batch of downstream packets from the switch.
This commit is contained in:
parent
2e6e2a06c1
commit
bd9a6bd625
@ -846,6 +846,13 @@ func (l *channelLink) htlcManager() {
|
|||||||
batchTick := l.cfg.BatchTicker.Start()
|
batchTick := l.cfg.BatchTicker.Start()
|
||||||
defer l.cfg.BatchTicker.Stop()
|
defer l.cfg.BatchTicker.Stop()
|
||||||
|
|
||||||
|
// We'll only need the batch ticker if we have outgoing updates that are
|
||||||
|
// not covered by our last signature. This value will be nil unless a
|
||||||
|
// downstream packet forces the batchCounter to be positive. After the
|
||||||
|
// batch is cleared, it will return to nil to prevent wasteful CPU time
|
||||||
|
// caused by the batch ticker waking up the htlcManager needlessly.
|
||||||
|
var maybeBatchTick <-chan time.Time
|
||||||
|
|
||||||
out:
|
out:
|
||||||
for {
|
for {
|
||||||
// We must always check if we failed at some point processing
|
// We must always check if we failed at some point processing
|
||||||
@ -926,10 +933,12 @@ out:
|
|||||||
break out
|
break out
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-batchTick:
|
case <-maybeBatchTick:
|
||||||
// If the current batch is empty, then we have no work
|
// If the current batch is empty, then we have no work
|
||||||
// here.
|
// here. We also disable the batch ticker from waking up
|
||||||
|
// the htlcManager while the batch is empty.
|
||||||
if l.batchCounter == 0 {
|
if l.batchCounter == 0 {
|
||||||
|
maybeBatchTick = nil
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -955,6 +964,13 @@ out:
|
|||||||
|
|
||||||
l.handleDownStreamPkt(packet, true)
|
l.handleDownStreamPkt(packet, true)
|
||||||
|
|
||||||
|
// If the downstream packet resulted in a non-empty
|
||||||
|
// batch, reinstate the batch ticker so that it can be
|
||||||
|
// cleared.
|
||||||
|
if l.batchCounter > 0 {
|
||||||
|
maybeBatchTick = batchTick
|
||||||
|
}
|
||||||
|
|
||||||
// A message from the switch was just received. This indicates
|
// A message from the switch was just received. This indicates
|
||||||
// that the link is an intermediate hop in a multi-hop HTLC
|
// that the link is an intermediate hop in a multi-hop HTLC
|
||||||
// circuit.
|
// circuit.
|
||||||
@ -977,6 +993,13 @@ out:
|
|||||||
|
|
||||||
l.handleDownStreamPkt(pkt, false)
|
l.handleDownStreamPkt(pkt, false)
|
||||||
|
|
||||||
|
// If the downstream packet resulted in a non-empty
|
||||||
|
// batch, reinstate the batch ticker so that it can be
|
||||||
|
// cleared.
|
||||||
|
if l.batchCounter > 0 {
|
||||||
|
maybeBatchTick = batchTick
|
||||||
|
}
|
||||||
|
|
||||||
// A message from the connected peer was just received. This
|
// A message from the connected peer was just received. This
|
||||||
// indicates that we have a new incoming HTLC, either directly
|
// indicates that we have a new incoming HTLC, either directly
|
||||||
// for us, or part of a multi-hop HTLC circuit.
|
// for us, or part of a multi-hop HTLC circuit.
|
||||||
|
Loading…
Reference in New Issue
Block a user