2023-06-22 11:55:30 +00:00
|
|
|
package benchmark
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"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
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func benchmarkPutSeq(b *testing.B, cache writecache.Cache, size uint64) {
|
|
|
|
benchmarkPutPrepare(b, cache)
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(b, cache.Close()) }()
|
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()
|
|
|
|
for n := 0; n < b.N; 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-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(b, cache.Close()) }()
|
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")
|
2023-08-09 12:54:08 +00:00
|
|
|
require.NoError(b, cache.Init(), "initializing")
|
|
|
|
}
|
|
|
|
|
|
|
|
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),
|
|
|
|
writecache.WithSmallObjectSize(128<<10),
|
2023-08-09 12:54:08 +00:00
|
|
|
)
|
|
|
|
}
|