|
4 | 4 | "context"
|
5 | 5 | "database/sql"
|
6 | 6 | "errors"
|
| 7 | + "fmt" |
7 | 8 | "os"
|
8 | 9 | "path"
|
9 | 10 | "sync"
|
@@ -620,3 +621,73 @@ func BenchmarkCacheLoading(b *testing.B) {
|
620 | 621 | })
|
621 | 622 | }
|
622 | 623 | }
|
| 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