Skip to content

Commit 5800a3e

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 f5ce4a5 commit 5800a3e

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"
@@ -620,3 +621,73 @@ func BenchmarkCacheLoading(b *testing.B) {
620621
})
621622
}
622623
}
624+
625+
// BenchmarkGraphReadMethods benchmarks various read calls of various V1Store
626+
// implementations.
627+
//
628+
// NOTE: this is to be run against a local graph database. It can be run
629+
// either against a kvdb-bbolt channel.db file, or a kvdb-sqlite channel.sqlite
630+
// file or a postgres connection containing the channel graph in kvdb format and
631+
// finally, it can be run against a native SQL sqlite or postgres database.
632+
//
633+
// NOTE: the TestPopulateDBs test helper can be used to populate a set of test
634+
// DBs from a single source db.
635+
func BenchmarkGraphReadMethods(b *testing.B) {
636+
ctx := context.Background()
637+
638+
backends := []dbConnection{
639+
kvdbBBoltConn,
640+
kvdbSqliteConn,
641+
nativeSQLSqliteConn,
642+
kvdbPostgresConn,
643+
nativeSQLPostgresConn,
644+
}
645+
646+
tests := []struct {
647+
name string
648+
fn func(b testing.TB, store V1Store)
649+
}{
650+
{
651+
name: "ForEachNode",
652+
fn: func(b testing.TB, store V1Store) {
653+
err := store.ForEachNode(
654+
ctx, func(_ NodeRTx) error {
655+
return nil
656+
}, func() {},
657+
)
658+
require.NoError(b, err)
659+
},
660+
},
661+
{
662+
name: "ForEachChannel",
663+
fn: func(b testing.TB, store V1Store) {
664+
//nolint:ll
665+
err := store.ForEachChannel(
666+
ctx, func(_ *models.ChannelEdgeInfo,
667+
_ *models.ChannelEdgePolicy,
668+
_ *models.ChannelEdgePolicy) error {
669+
670+
return nil
671+
}, func() {},
672+
)
673+
require.NoError(b, err)
674+
},
675+
},
676+
}
677+
678+
for _, test := range tests {
679+
for _, db := range backends {
680+
name := fmt.Sprintf("%s-%s", test.name, db.name)
681+
b.Run(name, func(b *testing.B) {
682+
store := db.open(b)
683+
684+
// Reset timer to exclude setup time.
685+
b.ResetTimer()
686+
687+
for i := 0; i < b.N; i++ {
688+
test.fn(b, store)
689+
}
690+
})
691+
}
692+
}
693+
}

0 commit comments

Comments
 (0)