Ekaterina Lebedeva
8a81af5a3b
All checks were successful
DCO action / DCO (pull_request) Successful in 1m38s
Build / Build Components (1.20) (pull_request) Successful in 4m22s
Build / Build Components (1.21) (pull_request) Successful in 4m25s
Vulncheck / Vulncheck (pull_request) Successful in 4m56s
Tests and linters / Lint (pull_request) Successful in 6m1s
Tests and linters / Tests (1.20) (pull_request) Successful in 7m43s
Tests and linters / Staticcheck (pull_request) Successful in 8m1s
Tests and linters / Tests (1.21) (pull_request) Successful in 8m14s
Tests and linters / Tests with -race (pull_request) Successful in 8m32s
Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
122 lines
3.6 KiB
Go
122 lines
3.6 KiB
Go
package benchmark
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/teststore"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebadger"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebbolt"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func BenchmarkWritecacheSeq(b *testing.B) {
|
|
const payloadSize = 8 << 10
|
|
b.Run("bbolt_seq", func(b *testing.B) {
|
|
benchmarkPutSeq(b, newBBoltCache(b), payloadSize)
|
|
})
|
|
b.Run("badger_seq", func(b *testing.B) {
|
|
benchmarkPutSeq(b, newBadgerCache(b), payloadSize)
|
|
})
|
|
}
|
|
|
|
func BenchmarkWritecachePar(b *testing.B) {
|
|
const payloadSize = 8 << 10
|
|
b.Run("bbolt_par", func(b *testing.B) {
|
|
benchmarkPutPar(b, newBBoltCache(b), payloadSize)
|
|
})
|
|
b.Run("badger_par", func(b *testing.B) {
|
|
benchmarkPutPar(b, newBadgerCache(b), payloadSize)
|
|
})
|
|
}
|
|
|
|
func benchmarkPutSeq(b *testing.B, cache writecache.Cache, size uint64) {
|
|
benchmarkPutPrepare(b, cache)
|
|
|
|
ctx := context.Background()
|
|
objGen := testutil.RandObjGenerator{ObjSize: size}
|
|
|
|
b.ResetTimer()
|
|
for n := 0; n < b.N; n++ {
|
|
obj := objGen.Next()
|
|
rawData, err := obj.Marshal()
|
|
require.NoError(b, err, "marshaling object")
|
|
prm := common.PutPrm{
|
|
Address: testutil.AddressFromObject(b, obj),
|
|
Object: obj,
|
|
RawData: rawData,
|
|
}
|
|
if _, err := cache.Put(ctx, prm); err != nil {
|
|
b.Fatalf("putting: %v", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func benchmarkPutPar(b *testing.B, cache writecache.Cache, size uint64) {
|
|
benchmarkPutPrepare(b, cache)
|
|
|
|
ctx := context.Background()
|
|
|
|
b.ResetTimer()
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
objGen := testutil.RandObjGenerator{ObjSize: size}
|
|
for pb.Next() {
|
|
obj := objGen.Next()
|
|
rawData, err := obj.Marshal()
|
|
require.NoError(b, err, "marshaling object")
|
|
prm := common.PutPrm{
|
|
Address: testutil.AddressFromObject(b, obj),
|
|
Object: obj,
|
|
RawData: rawData,
|
|
}
|
|
if _, err := cache.Put(ctx, prm); err != nil {
|
|
b.Fatalf("putting: %v", err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
func benchmarkPutPrepare(b *testing.B, cache writecache.Cache) {
|
|
require.NoError(b, cache.Open(context.Background(), false), "opening")
|
|
require.NoError(b, cache.Init(), "initializing")
|
|
b.Cleanup(func() {
|
|
require.NoError(b, cache.Close(), "closing")
|
|
})
|
|
}
|
|
|
|
type testMetabase struct{}
|
|
|
|
func (testMetabase) UpdateStorageID(meta.UpdateStorageIDPrm) (meta.UpdateStorageIDRes, error) {
|
|
return meta.UpdateStorageIDRes{}, nil
|
|
}
|
|
|
|
func newBBoltCache(b *testing.B) writecache.Cache {
|
|
bs := teststore.New(
|
|
teststore.WithPut(func(pp common.PutPrm) (common.PutRes, error) { return common.PutRes{}, nil }),
|
|
)
|
|
return writecachebbolt.New(
|
|
writecachebbolt.WithPath(b.TempDir()),
|
|
writecachebbolt.WithBlobstor(bs),
|
|
writecachebbolt.WithMetabase(testMetabase{}),
|
|
writecachebbolt.WithMaxCacheSize(256<<30),
|
|
writecachebbolt.WithSmallObjectSize(128<<10),
|
|
)
|
|
}
|
|
|
|
func newBadgerCache(b *testing.B) writecache.Cache {
|
|
bs := teststore.New(
|
|
teststore.WithPut(func(pp common.PutPrm) (common.PutRes, error) { return common.PutRes{}, nil }),
|
|
)
|
|
return writecachebadger.New(
|
|
writecachebadger.WithPath(b.TempDir()),
|
|
writecachebadger.WithBlobstor(bs),
|
|
writecachebadger.WithMetabase(testMetabase{}),
|
|
writecachebadger.WithMaxCacheSize(256<<30),
|
|
writecachebadger.WithGCInterval(10*time.Second),
|
|
)
|
|
}
|