Skip to content

Commit a8695e1

Browse files
committed
graph/db: benchmark various graph read calls
This commit adds benchmark tests for the ForEachNode and ForEachChannel DB calls which are called by DescribeGraph.
1 parent dc2bf3c commit a8695e1

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

graph/db/benchmark_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"database/sql"
66
"errors"
7+
"fmt"
78
"os"
89
"path"
910
"sync"
@@ -609,3 +610,73 @@ func BenchmarkCacheLoading(b *testing.B) {
609610
})
610611
}
611612
}
613+
614+
// BenchmarkGraphReadMethods benchmarks various read calls of various V1Store
615+
// implementations.
616+
//
617+
// NOTE: this is to be run against a local graph database. It can be run
618+
// either against a kvdb-bbolt channel.db file, or a kvdb-sqlite channel.sqlite
619+
// file or a postgres connection containing the channel graph in kvdb format and
620+
// finally, it can be run against a native SQL sqlite or postgres database.
621+
//
622+
// NOTE: the TestPopulateDBs test helper can be used to populate a set of test
623+
// DBs from a single source db.
624+
func BenchmarkGraphReadMethods(b *testing.B) {
625+
ctx := context.Background()
626+
627+
backends := []dbConnection{
628+
kvdbBBoltConn,
629+
kvdbSqliteConn,
630+
nativeSQLSqliteConn,
631+
kvdbPostgresConn,
632+
nativeSQLPostgresConn,
633+
}
634+
635+
tests := []struct {
636+
name string
637+
fn func(b testing.TB, store V1Store)
638+
}{
639+
{
640+
name: "ForEachNode",
641+
fn: func(b testing.TB, store V1Store) {
642+
err := store.ForEachNode(
643+
ctx, func(_ NodeRTx) error {
644+
return nil
645+
}, func() {},
646+
)
647+
require.NoError(b, err)
648+
},
649+
},
650+
{
651+
name: "ForEachChannel",
652+
fn: func(b testing.TB, store V1Store) {
653+
//nolint:ll
654+
err := store.ForEachChannel(
655+
ctx, func(_ *models.ChannelEdgeInfo,
656+
_ *models.ChannelEdgePolicy,
657+
_ *models.ChannelEdgePolicy) error {
658+
659+
return nil
660+
}, func() {},
661+
)
662+
require.NoError(b, err)
663+
},
664+
},
665+
}
666+
667+
for _, test := range tests {
668+
for _, db := range backends {
669+
name := fmt.Sprintf("%s-%s", test.name, db.name)
670+
b.Run(name, func(b *testing.B) {
671+
store := db.open(b)
672+
673+
// Reset timer to exclude setup time.
674+
b.ResetTimer()
675+
676+
for i := 0; i < b.N; i++ {
677+
test.fn(b, store)
678+
}
679+
})
680+
}
681+
}
682+
}

0 commit comments

Comments
 (0)