forked from TrueCloudLab/frostfs-node
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package benchmark
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
|
"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"
|
|
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
|
)
|
|
|
|
func BenchmarkWritecache(b *testing.B) {
|
|
b.Run("bbolt", func(b *testing.B) {
|
|
cache := writecachebbolt.New(
|
|
writecachebbolt.WithPath(b.TempDir()),
|
|
)
|
|
benchmarkPut(b, cache)
|
|
})
|
|
b.Run("badger", func(b *testing.B) {
|
|
cache := writecachebadger.New(
|
|
writecachebadger.WithPath(b.TempDir()),
|
|
)
|
|
benchmarkPut(b, cache)
|
|
})
|
|
}
|
|
|
|
func benchmarkPut(b *testing.B, cache writecache.Cache) {
|
|
if err := cache.Open(false); err != nil {
|
|
b.Fatalf("initializing: %v", err)
|
|
}
|
|
if err := cache.Init(); err != nil {
|
|
b.Fatalf("opening: %v", err)
|
|
}
|
|
defer cache.Close()
|
|
|
|
ctx := context.Background()
|
|
objGen := testutil.RandObjGenerator{ObjSize: 8 << 10}
|
|
|
|
b.ResetTimer()
|
|
for n := 0; n < b.N; n++ {
|
|
prm := common.PutPrm{
|
|
Address: oidtest.Address(),
|
|
Object: objGen.Next(),
|
|
}
|
|
if _, err := cache.Put(ctx, prm); err != nil {
|
|
b.Fatalf("putting: %v", err)
|
|
}
|
|
}
|
|
}
|