[#1146] engine: Add benchmarks for exists

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-02-22 10:35:53 +03:00 committed by Alex Vanin
parent 0e0a675f35
commit dab6bcabe4

View file

@ -4,6 +4,7 @@ import (
"crypto/sha256" "crypto/sha256"
"fmt" "fmt"
"math/rand" "math/rand"
"os"
"path/filepath" "path/filepath"
"sync" "sync"
"testing" "testing"
@ -16,7 +17,9 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/util/test" "github.com/nspcc-dev/neofs-node/pkg/util/test"
"github.com/nspcc-dev/neofs-sdk-go/checksum" "github.com/nspcc-dev/neofs-sdk-go/checksum"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test"
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/owner"
ownertest "github.com/nspcc-dev/neofs-sdk-go/owner/test" ownertest "github.com/nspcc-dev/neofs-sdk-go/owner/test"
@ -28,6 +31,49 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
func BenchmarkExists(b *testing.B) {
b.Run("2 shards", func(b *testing.B) {
benchmarkExists(b, 2)
})
b.Run("4 shards", func(b *testing.B) {
benchmarkExists(b, 4)
})
b.Run("8 shards", func(b *testing.B) {
benchmarkExists(b, 8)
})
}
func benchmarkExists(b *testing.B, shardNum int) {
shards := make([]*shard.Shard, shardNum)
for i := 0; i < shardNum; i++ {
shards[i] = testNewShard(b, i)
}
e := testNewEngineWithShards(shards...)
b.Cleanup(func() {
_ = e.Close()
_ = os.RemoveAll(b.Name())
})
addr := objecttest.Address()
for i := 0; i < 100; i++ {
obj := generateRawObjectWithCID(b, cidtest.ID())
err := Put(e, obj.Object())
if err != nil {
b.Fatal(err)
}
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
ok, err := e.exists(addr)
if err != nil || ok {
b.Fatalf("%t %v", ok, err)
}
}
}
func testNewEngineWithShards(shards ...*shard.Shard) *StorageEngine { func testNewEngineWithShards(shards ...*shard.Shard) *StorageEngine {
engine := &StorageEngine{ engine := &StorageEngine{
cfg: &cfg{ cfg: &cfg{
@ -54,7 +100,7 @@ func testNewEngineWithShards(shards ...*shard.Shard) *StorageEngine {
return engine return engine
} }
func testNewShard(t *testing.T, id int) *shard.Shard { func testNewShard(t testing.TB, id int) *shard.Shard {
sid, err := generateShardID() sid, err := generateShardID()
require.NoError(t, err) require.NoError(t, err)
@ -88,7 +134,7 @@ func testOID() *oidSDK.ID {
return id return id
} }
func generateRawObjectWithCID(t *testing.T, cid *cid.ID) *object.RawObject { func generateRawObjectWithCID(t testing.TB, cid *cid.ID) *object.RawObject {
version := version.New() version := version.New()
version.SetMajor(2) version.SetMajor(2)
version.SetMinor(1) version.SetMinor(1)