Skip to content

Commit 0bbe463

Browse files
committed
graph/db: benchmark DescribeGraph calls
This commit adds benchmark tests for the ForEachNode and ForEachChannel DB calls which are called by DescribeGraph.
1 parent 367fe05 commit 0bbe463

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

graph/db/benchmark_test.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,3 +602,102 @@ func BenchmarkCacheLoading(b *testing.B) {
602602
})
603603
}
604604
}
605+
606+
// BenchmarkForEachNode benchmarks the ForEachNode method of the ChannelGraph
607+
// by iterating over all nodes in the graph and executing a no-op function for
608+
// each node. This is useful to measure the performance of iterating over
609+
// nodes in the graph.
610+
//
611+
// NOTE: this is to be run against a local graph database. It can be run
612+
// either against a kvdb-bbolt channel.db file, or a kvdb-sqlite channel.sqlite
613+
// file or a postgres connection containing the channel graph in kvdb format and
614+
// finally, it can be run against a native SQL sqlite or postgres database.
615+
func BenchmarkForEachNode(b *testing.B) {
616+
ctx := context.Background()
617+
618+
tests := []dbConnection{
619+
kvdbBBoltConn,
620+
kvdbSqliteConn,
621+
nativeSQLSqliteConn,
622+
kvdbPostgresConn,
623+
nativeSQLPostgresConn,
624+
}
625+
626+
for _, test := range tests {
627+
b.Run(test.name, func(b *testing.B) {
628+
graph, err := NewChannelGraph(
629+
test.open(b), WithUseGraphCache(false),
630+
)
631+
require.NoError(b, err)
632+
require.NoError(b, graph.Start())
633+
634+
// Reset timer to exclude setup time.
635+
b.ResetTimer()
636+
637+
for i := 0; i < b.N; i++ {
638+
err = graph.ForEachNode(
639+
ctx, func(_ NodeRTx) error {
640+
return nil
641+
}, func() {},
642+
)
643+
require.NoError(b, err)
644+
645+
b.StopTimer()
646+
require.NoError(b, graph.Stop())
647+
b.StartTimer()
648+
}
649+
})
650+
}
651+
}
652+
653+
// BenchmarkForEachChannelAndPolicy benchmarks the ForEachChannel method of the
654+
// ChannelGraph by iterating over all channels and their policies in the graph
655+
// and executing a no-op function for each channel and policy. This is useful
656+
// to measure the performance of iterating over channels and policies in the
657+
// graph.
658+
//
659+
// NOTE: this is to be run against a local graph database. It can be run
660+
// either against a kvdb-bbolt channel.db file, or a kvdb-sqlite channel.sqlite
661+
// file or a postgres connection containing the channel graph in kvdb format and
662+
// finally, it can be run against a native SQL sqlite or postgres database.
663+
func BenchmarkForEachChannelAndPolicy(b *testing.B) {
664+
ctx := context.Background()
665+
666+
tests := []dbConnection{
667+
kvdbBBoltConn,
668+
kvdbSqliteConn,
669+
nativeSQLSqliteConn,
670+
kvdbPostgresConn,
671+
nativeSQLPostgresConn,
672+
}
673+
674+
for _, test := range tests {
675+
b.Run(test.name, func(b *testing.B) {
676+
graph, err := NewChannelGraph(
677+
test.open(b), WithUseGraphCache(false),
678+
)
679+
require.NoError(b, err)
680+
require.NoError(b, graph.Start())
681+
682+
// Reset timer to exclude setup time.
683+
b.ResetTimer()
684+
685+
for i := 0; i < b.N; i++ {
686+
//nolint:ll
687+
err = graph.ForEachChannel(
688+
ctx, func(_ *models.ChannelEdgeInfo,
689+
_ *models.ChannelEdgePolicy,
690+
_ *models.ChannelEdgePolicy) error {
691+
692+
return nil
693+
}, func() {},
694+
)
695+
require.NoError(b, err)
696+
697+
b.StopTimer()
698+
require.NoError(b, graph.Stop())
699+
b.StartTimer()
700+
}
701+
})
702+
}
703+
}

0 commit comments

Comments
 (0)