routing: log performance metrics

This commit is contained in:
Joost Jager 2019-09-06 08:56:59 +02:00
parent 989de44a69
commit 9f3656efeb
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -4,6 +4,7 @@ import (
"container/heap" "container/heap"
"fmt" "fmt"
"math" "math"
"time"
"github.com/coreos/bbolt" "github.com/coreos/bbolt"
@ -296,6 +297,18 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
source, target route.Vertex, amt lnwire.MilliSatoshi) ( source, target route.Vertex, amt lnwire.MilliSatoshi) (
[]*channeldb.ChannelEdgePolicy, error) { []*channeldb.ChannelEdgePolicy, error) {
// Pathfinding can be a significant portion of the total payment
// latency, especially on low-powered devices. Log several metrics to
// aid in the analysis performance problems in this area.
start := time.Now()
nodesVisited := 0
edgesExpanded := 0
defer func() {
timeElapsed := time.Since(start)
log.Debugf("Pathfinding perf metrics: nodes=%v, edges=%v, "+
"time=%v", nodesVisited, edgesExpanded, timeElapsed)
}()
var err error var err error
tx := g.tx tx := g.tx
if tx == nil { if tx == nil {
@ -402,6 +415,8 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
processEdge := func(fromVertex route.Vertex, bandwidth lnwire.MilliSatoshi, processEdge := func(fromVertex route.Vertex, bandwidth lnwire.MilliSatoshi,
edge *channeldb.ChannelEdgePolicy, toNode route.Vertex) { edge *channeldb.ChannelEdgePolicy, toNode route.Vertex) {
edgesExpanded++
// If this is not a local channel and it is disabled, we will // If this is not a local channel and it is disabled, we will
// skip it. // skip it.
// TODO(halseth): also ignore disable flags for non-local // TODO(halseth): also ignore disable flags for non-local
@ -573,6 +588,8 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
heap.Push(&nodeHeap, distance[target]) heap.Push(&nodeHeap, distance[target])
for nodeHeap.Len() != 0 { for nodeHeap.Len() != 0 {
nodesVisited++
// Fetch the node within the smallest distance from our source // Fetch the node within the smallest distance from our source
// from the heap. // from the heap.
partialPath := heap.Pop(&nodeHeap).(nodeWithDist) partialPath := heap.Pop(&nodeHeap).(nodeWithDist)