4
4
"context"
5
5
"database/sql"
6
6
"errors"
7
+ "fmt"
7
8
"os"
8
9
"path"
9
10
"sync"
@@ -30,8 +31,8 @@ const (
30
31
bboltDBPath = "testdata/kvdb"
31
32
kvdbSqlitePath = "testdata/kvdb"
32
33
nativeSQLSqlitePath = "testdata"
33
- kvdbPostgresDNS = "postgres://test @localhost/graphbenchmark_kvdb"
34
- nativeSQLPostgresDNS = "postgres://test @localhost/graphbenchmark"
34
+ kvdbPostgresDNS = "postgres://ellemouton @localhost/graphbenchmark_kvdb"
35
+ nativeSQLPostgresDNS = "postgres://ellemouton @localhost/graphbenchmark"
35
36
36
37
kvdbSqliteFile = "channel.sqlite"
37
38
kvdbBBoltFile = "channel.db"
@@ -609,3 +610,73 @@ func BenchmarkCacheLoading(b *testing.B) {
609
610
})
610
611
}
611
612
}
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