Skip to content

Commit dc2bf3c

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

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

graph/db/benchmark_test.go

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

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

0 commit comments

Comments
 (0)