mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-30 07:35:07 +02:00
graph/db: cover more DB methods in benchmark test
So that we can properly measure upcoming performance improvements.
This commit is contained in:
@@ -19,6 +19,8 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/kvdb/postgres"
|
"github.com/lightningnetwork/lnd/kvdb/postgres"
|
||||||
"github.com/lightningnetwork/lnd/kvdb/sqlbase"
|
"github.com/lightningnetwork/lnd/kvdb/sqlbase"
|
||||||
"github.com/lightningnetwork/lnd/kvdb/sqlite"
|
"github.com/lightningnetwork/lnd/kvdb/sqlite"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
"github.com/lightningnetwork/lnd/sqldb"
|
"github.com/lightningnetwork/lnd/sqldb"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
@@ -643,6 +645,10 @@ func BenchmarkGraphReadMethods(b *testing.B) {
|
|||||||
nativeSQLPostgresConn,
|
nativeSQLPostgresConn,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We use a counter to make sure that any call-back is doing something
|
||||||
|
// useful, otherwise the compiler may optimize it away in the future.
|
||||||
|
var counter int64
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
fn func(b testing.TB, store V1Store)
|
fn func(b testing.TB, store V1Store)
|
||||||
@@ -652,6 +658,11 @@ func BenchmarkGraphReadMethods(b *testing.B) {
|
|||||||
fn: func(b testing.TB, store V1Store) {
|
fn: func(b testing.TB, store V1Store) {
|
||||||
err := store.ForEachNode(
|
err := store.ForEachNode(
|
||||||
ctx, func(_ NodeRTx) error {
|
ctx, func(_ NodeRTx) error {
|
||||||
|
// Increment the counter to
|
||||||
|
// ensure the callback is doing
|
||||||
|
// something.
|
||||||
|
counter++
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}, func() {},
|
}, func() {},
|
||||||
)
|
)
|
||||||
@@ -667,6 +678,11 @@ func BenchmarkGraphReadMethods(b *testing.B) {
|
|||||||
_ *models.ChannelEdgePolicy,
|
_ *models.ChannelEdgePolicy,
|
||||||
_ *models.ChannelEdgePolicy) error {
|
_ *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
|
// Increment the counter to
|
||||||
|
// ensure the callback is doing
|
||||||
|
// something.
|
||||||
|
counter++
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}, func() {},
|
}, func() {},
|
||||||
)
|
)
|
||||||
@@ -682,6 +698,43 @@ func BenchmarkGraphReadMethods(b *testing.B) {
|
|||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "ForEachNodeCacheable",
|
||||||
|
fn: func(b testing.TB, store V1Store) {
|
||||||
|
err := store.ForEachNodeCacheable(
|
||||||
|
ctx, func(_ route.Vertex,
|
||||||
|
_ *lnwire.FeatureVector) error {
|
||||||
|
|
||||||
|
// Increment the counter to
|
||||||
|
// ensure the callback is doing
|
||||||
|
// something.
|
||||||
|
counter++
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}, func() {},
|
||||||
|
)
|
||||||
|
require.NoError(b, err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ForEachNodeCached",
|
||||||
|
fn: func(b testing.TB, store V1Store) {
|
||||||
|
//nolint:ll
|
||||||
|
err := store.ForEachNodeCached(
|
||||||
|
ctx, func(route.Vertex,
|
||||||
|
map[uint64]*DirectedChannel) error {
|
||||||
|
|
||||||
|
// Increment the counter to
|
||||||
|
// ensure the callback is doing
|
||||||
|
// something.
|
||||||
|
counter++
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}, func() {},
|
||||||
|
)
|
||||||
|
require.NoError(b, err)
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
Reference in New Issue
Block a user