Skip to content

Commit 367fe05

Browse files
committed
graph/db: add BenchmarkCacheLoading
Add a benchmark test to test graph cache loading against various local graph DBs.
1 parent a996e2f commit 367fe05

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

graph/db/benchmark_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,38 @@ func syncGraph(t *testing.T, src, dest *ChannelGraph) {
567567

568568
t.Logf("Done syncing %d channels", total)
569569
}
570+
571+
// BenchmarkCacheLoading benchmarks how long it takes to load the in-memory
572+
// graph cache from a populated database.
573+
//
574+
// NOTE: this is to be run against a local graph database. It can be run
575+
// either against a kvdb-bbolt channel.db file, or a kvdb-sqlite channel.sqlite
576+
// file or a postgres connection containing the channel graph in kvdb format and
577+
// finally, it can be run against a native SQL sqlite or postgres database.
578+
func BenchmarkCacheLoading(b *testing.B) {
579+
ctx := context.Background()
580+
581+
tests := []dbConnection{
582+
kvdbBBoltConn,
583+
kvdbSqliteConn,
584+
nativeSQLSqliteConn,
585+
kvdbPostgresConn,
586+
nativeSQLPostgresConn,
587+
}
588+
589+
for _, test := range tests {
590+
b.Run(test.name, func(b *testing.B) {
591+
store := test.open(b)
592+
593+
// Reset timer to exclude setup time.
594+
b.ResetTimer()
595+
596+
for i := 0; i < b.N; i++ {
597+
graph, err := NewChannelGraph(store)
598+
require.NoError(b, err)
599+
600+
require.NoError(b, graph.populateCache(ctx))
601+
}
602+
})
603+
}
604+
}

0 commit comments

Comments
 (0)