[#2061] node: Unify meta.Get benchmarks

Make them get exactly one (different) object per a bench iteration.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-11-30 15:17:02 +03:00 committed by fyrchik
parent bc905f169d
commit 3d0768a1d3

View file

@ -4,7 +4,9 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"os" "os"
"runtime"
"testing" "testing"
"time"
"github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/core/object"
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
@ -171,6 +173,10 @@ func BenchmarkGet(b *testing.B) {
100, 100,
} }
defer func() {
_ = os.RemoveAll(b.Name())
}()
for _, num := range numOfObjects { for _, num := range numOfObjects {
b.Run(fmt.Sprintf("%d_objects", num), func(b *testing.B) { b.Run(fmt.Sprintf("%d_objects", num), func(b *testing.B) {
benchmarkGet(b, num) benchmarkGet(b, num)
@ -181,7 +187,11 @@ func BenchmarkGet(b *testing.B) {
var obj *objectSDK.Object var obj *objectSDK.Object
func benchmarkGet(b *testing.B, numOfObj int) { func benchmarkGet(b *testing.B, numOfObj int) {
db := newDB(b) prepareDb := func(batchSize int) (*meta.DB, []oid.Address) {
db := newDB(b,
meta.WithMaxBatchSize(batchSize),
meta.WithMaxBatchDelay(10*time.Millisecond),
)
addrs := make([]oid.Address, 0, numOfObj) addrs := make([]oid.Address, 0, numOfObj)
for i := 0; i < numOfObj; i++ { for i := 0; i < numOfObj; i++ {
@ -192,38 +202,44 @@ func benchmarkGet(b *testing.B, numOfObj int) {
require.NoError(b, err) require.NoError(b, err)
} }
b.Cleanup(func() { return db, addrs
_ = db.Close() }
_ = os.RemoveAll(b.Name())
})
var err error db, addrs := prepareDb(runtime.NumCPU())
var getPrm meta.GetPrm
getPrm.SetAddress(addrs[len(addrs)/2])
b.Run("parallel", func(b *testing.B) { b.Run("parallel", func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
for pb.Next() { var counter int
_, err = db.Get(getPrm)
if err != nil {
b.Fatal(err)
}
}
})
})
b.Run("serial", func(b *testing.B) { for pb.Next() {
b.ReportAllocs() var getPrm meta.GetPrm
for i := 0; i < b.N; i++ { getPrm.SetAddress(addrs[counter%len(addrs)])
for _, addr := range addrs { counter++
getPrm.SetAddress(addr)
_, err := db.Get(getPrm) _, err := db.Get(getPrm)
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }
} }
})
})
require.NoError(b, db.Close())
require.NoError(b, os.RemoveAll(b.Name()))
db, addrs = prepareDb(1)
b.Run("serial", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
var getPrm meta.GetPrm
getPrm.SetAddress(addrs[i%len(addrs)])
_, err := db.Get(getPrm)
if err != nil {
b.Fatal(err)
}
} }
}) })
} }