2023-06-22 11:55:30 +00:00
|
|
|
package benchmark
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-08-08 10:15:22 +00:00
|
|
|
"fmt"
|
2023-06-22 11:55:30 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
2023-08-09 12:54:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/teststore"
|
2023-06-22 11:55:30 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
2023-08-09 12:54:08 +00:00
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
2024-02-09 06:17:17 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
2023-06-22 11:55:30 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache"
|
2023-08-09 12:54:08 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-06-22 11:55:30 +00:00
|
|
|
)
|
|
|
|
|
2023-08-09 12:54:08 +00:00
|
|
|
func BenchmarkWritecacheSeq(b *testing.B) {
|
|
|
|
const payloadSize = 8 << 10
|
|
|
|
b.Run("bbolt_seq", func(b *testing.B) {
|
2023-12-22 09:58:20 +00:00
|
|
|
benchmarkPutSeq(b, newCache(b), payloadSize)
|
2023-06-22 11:55:30 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-08-09 12:54:08 +00:00
|
|
|
func BenchmarkWritecachePar(b *testing.B) {
|
|
|
|
const payloadSize = 8 << 10
|
|
|
|
b.Run("bbolt_par", func(b *testing.B) {
|
2023-12-22 09:58:20 +00:00
|
|
|
benchmarkPutPar(b, newCache(b), payloadSize)
|
2023-08-09 12:54:08 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-08-08 10:15:22 +00:00
|
|
|
func BenchmarkWriteAfterDelete(b *testing.B) {
|
|
|
|
const payloadSize = 32 << 10
|
|
|
|
const parallel = 25
|
|
|
|
|
|
|
|
cache := newCache(b)
|
|
|
|
benchmarkPutPrepare(b, cache)
|
|
|
|
b.Run(fmt.Sprintf("%dB_before", payloadSize), func(b *testing.B) {
|
|
|
|
b.SetParallelism(parallel)
|
|
|
|
benchmarkRunPar(b, cache, payloadSize)
|
|
|
|
})
|
|
|
|
require.NoError(b, cache.Flush(context.Background(), false, false))
|
|
|
|
b.Run(fmt.Sprintf("%dB_after", payloadSize), func(b *testing.B) {
|
|
|
|
b.SetParallelism(parallel)
|
|
|
|
benchmarkRunPar(b, cache, payloadSize)
|
|
|
|
})
|
2024-10-21 13:27:28 +00:00
|
|
|
require.NoError(b, cache.Close(context.Background()))
|
2024-08-08 10:15:22 +00:00
|
|
|
}
|
|
|
|
|
2023-08-09 12:54:08 +00:00
|
|
|
func benchmarkPutSeq(b *testing.B, cache writecache.Cache, size uint64) {
|
|
|
|
benchmarkPutPrepare(b, cache)
|
2024-10-21 13:27:28 +00:00
|
|
|
defer func() { require.NoError(b, cache.Close(context.Background())) }()
|
2023-06-22 11:55:30 +00:00
|
|
|
|
|
|
|
ctx := context.Background()
|
2023-08-09 12:54:08 +00:00
|
|
|
objGen := testutil.RandObjGenerator{ObjSize: size}
|
2023-06-22 11:55:30 +00:00
|
|
|
|
|
|
|
b.ResetTimer()
|
2024-08-30 16:20:55 +00:00
|
|
|
for range b.N {
|
2023-08-09 12:54:08 +00:00
|
|
|
obj := objGen.Next()
|
|
|
|
rawData, err := obj.Marshal()
|
|
|
|
require.NoError(b, err, "marshaling object")
|
2023-06-22 11:55:30 +00:00
|
|
|
prm := common.PutPrm{
|
2023-08-09 12:54:08 +00:00
|
|
|
Address: testutil.AddressFromObject(b, obj),
|
|
|
|
Object: obj,
|
|
|
|
RawData: rawData,
|
2023-06-22 11:55:30 +00:00
|
|
|
}
|
|
|
|
if _, err := cache.Put(ctx, prm); err != nil {
|
|
|
|
b.Fatalf("putting: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-08-09 12:54:08 +00:00
|
|
|
|
|
|
|
func benchmarkPutPar(b *testing.B, cache writecache.Cache, size uint64) {
|
|
|
|
benchmarkPutPrepare(b, cache)
|
2024-10-21 13:27:28 +00:00
|
|
|
defer func() { require.NoError(b, cache.Close(context.Background())) }()
|
2023-08-09 12:54:08 +00:00
|
|
|
|
2024-08-08 10:15:22 +00:00
|
|
|
benchmarkRunPar(b, cache, size)
|
|
|
|
}
|
|
|
|
|
|
|
|
func benchmarkRunPar(b *testing.B, cache writecache.Cache, size uint64) {
|
2023-08-09 12:54:08 +00:00
|
|
|
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) {
|
2024-02-09 06:17:17 +00:00
|
|
|
require.NoError(b, cache.Open(context.Background(), mode.ReadWrite), "opening")
|
2024-10-21 13:27:28 +00:00
|
|
|
require.NoError(b, cache.Init(context.Background()), "initializing")
|
2023-08-09 12:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type testMetabase struct{}
|
|
|
|
|
2023-10-13 11:01:14 +00:00
|
|
|
func (testMetabase) UpdateStorageID(context.Context, meta.UpdateStorageIDPrm) (meta.UpdateStorageIDRes, error) {
|
2023-08-09 12:54:08 +00:00
|
|
|
return meta.UpdateStorageIDRes{}, nil
|
|
|
|
}
|
|
|
|
|
2023-12-22 09:58:20 +00:00
|
|
|
func newCache(b *testing.B) writecache.Cache {
|
2023-08-09 12:54:08 +00:00
|
|
|
bs := teststore.New(
|
|
|
|
teststore.WithPut(func(pp common.PutPrm) (common.PutRes, error) { return common.PutRes{}, nil }),
|
|
|
|
)
|
2023-12-22 09:58:20 +00:00
|
|
|
return writecache.New(
|
|
|
|
writecache.WithPath(b.TempDir()),
|
|
|
|
writecache.WithBlobstor(bs),
|
|
|
|
writecache.WithMetabase(testMetabase{}),
|
|
|
|
writecache.WithMaxCacheSize(256<<30),
|
2023-08-09 12:54:08 +00:00
|
|
|
)
|
|
|
|
}
|