2023-03-03 09:33:08 +00:00
|
|
|
package blobstor
|
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
2023-03-03 09:33:08 +00:00
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobovniczatree"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/memstore"
|
2023-03-20 14:10:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
2024-06-04 13:28:47 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
2023-03-03 09:33:08 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-04-11 17:51:58 +00:00
|
|
|
"golang.org/x/sync/errgroup"
|
2023-03-03 09:33:08 +00:00
|
|
|
)
|
|
|
|
|
2023-04-11 17:20:32 +00:00
|
|
|
type storage struct {
|
|
|
|
desc string
|
|
|
|
create func(string) common.Storage
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s storage) open(b *testing.B) common.Storage {
|
2023-05-05 07:38:59 +00:00
|
|
|
st := s.create(b.TempDir())
|
2023-04-11 17:20:32 +00:00
|
|
|
|
2024-06-04 13:28:47 +00:00
|
|
|
require.NoError(b, st.Open(mode.ComponentReadWrite))
|
2023-04-11 17:20:32 +00:00
|
|
|
require.NoError(b, st.Init())
|
|
|
|
|
|
|
|
return st
|
|
|
|
}
|
|
|
|
|
2023-03-03 09:33:08 +00:00
|
|
|
// The storages to benchmark. Each storage has a description and a function which returns the actual
|
|
|
|
// storage along with a cleanup function.
|
2023-04-11 17:20:32 +00:00
|
|
|
var storages = []storage{
|
2023-03-03 09:33:08 +00:00
|
|
|
{
|
|
|
|
desc: "memstore",
|
2023-04-11 17:20:32 +00:00
|
|
|
create: func(string) common.Storage {
|
|
|
|
return memstore.New()
|
2023-03-03 09:33:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "fstree_nosync",
|
2023-04-11 17:20:32 +00:00
|
|
|
create: func(dir string) common.Storage {
|
2023-03-03 09:33:08 +00:00
|
|
|
return fstree.New(
|
|
|
|
fstree.WithPath(dir),
|
|
|
|
fstree.WithDepth(2),
|
|
|
|
fstree.WithDirNameLen(2),
|
|
|
|
fstree.WithNoSync(true),
|
2023-04-11 17:20:32 +00:00
|
|
|
)
|
2023-03-03 09:33:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-08-11 08:32:43 +00:00
|
|
|
desc: "fstree_without_object_counter",
|
2023-04-11 17:20:32 +00:00
|
|
|
create: func(dir string) common.Storage {
|
2023-03-03 09:33:08 +00:00
|
|
|
return fstree.New(
|
|
|
|
fstree.WithPath(dir),
|
|
|
|
fstree.WithDepth(2),
|
|
|
|
fstree.WithDirNameLen(2),
|
2023-04-11 17:20:32 +00:00
|
|
|
)
|
2023-03-03 09:33:08 +00:00
|
|
|
},
|
|
|
|
},
|
2023-08-11 08:32:43 +00:00
|
|
|
{
|
|
|
|
desc: "fstree_with_object_counter",
|
|
|
|
create: func(dir string) common.Storage {
|
|
|
|
return fstree.New(
|
|
|
|
fstree.WithPath(dir),
|
|
|
|
fstree.WithDepth(2),
|
|
|
|
fstree.WithDirNameLen(2),
|
|
|
|
fstree.WithFileCounter(fstree.NewSimpleCounter()),
|
|
|
|
)
|
|
|
|
},
|
|
|
|
},
|
2023-03-03 09:33:08 +00:00
|
|
|
{
|
|
|
|
desc: "blobovniczatree",
|
2023-04-11 17:20:32 +00:00
|
|
|
create: func(dir string) common.Storage {
|
2023-03-03 09:33:08 +00:00
|
|
|
return blobovniczatree.NewBlobovniczaTree(
|
2024-03-01 11:43:26 +00:00
|
|
|
context.Background(),
|
2023-03-03 09:33:08 +00:00
|
|
|
blobovniczatree.WithRootPath(dir),
|
2023-04-11 17:20:32 +00:00
|
|
|
)
|
2023-03-03 09:33:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkSubstorageReadPerf(b *testing.B) {
|
|
|
|
readTests := []struct {
|
|
|
|
desc string
|
|
|
|
size int
|
2023-03-20 14:10:26 +00:00
|
|
|
objGen func() testutil.ObjectGenerator
|
|
|
|
addrGen func() testutil.AddressGenerator
|
2023-03-03 09:33:08 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "seq100",
|
|
|
|
size: 10000,
|
2023-03-20 14:10:26 +00:00
|
|
|
objGen: func() testutil.ObjectGenerator { return &testutil.SeqObjGenerator{ObjSize: 100} },
|
|
|
|
addrGen: func() testutil.AddressGenerator { return &testutil.SeqAddrGenerator{MaxID: 100} },
|
2023-03-03 09:33:08 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "rand100",
|
|
|
|
size: 10000,
|
2023-03-20 14:10:26 +00:00
|
|
|
objGen: func() testutil.ObjectGenerator { return &testutil.SeqObjGenerator{ObjSize: 100} },
|
|
|
|
addrGen: func() testutil.AddressGenerator { return testutil.RandAddrGenerator(10000) },
|
2023-03-03 09:33:08 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range readTests {
|
|
|
|
for _, stEntry := range storages {
|
|
|
|
b.Run(fmt.Sprintf("%s-%s", stEntry.desc, tt.desc), func(b *testing.B) {
|
|
|
|
objGen := tt.objGen()
|
2023-04-11 17:20:32 +00:00
|
|
|
st := stEntry.open(b)
|
2024-10-21 13:27:28 +00:00
|
|
|
defer func() { require.NoError(b, st.Close(context.Background())) }()
|
2023-03-03 09:33:08 +00:00
|
|
|
|
|
|
|
// Fill database
|
2023-04-11 17:51:58 +00:00
|
|
|
var errG errgroup.Group
|
2024-08-30 16:20:55 +00:00
|
|
|
for range tt.size {
|
2023-03-03 09:33:08 +00:00
|
|
|
obj := objGen.Next()
|
2023-03-28 14:16:03 +00:00
|
|
|
addr := testutil.AddressFromObject(b, obj)
|
2023-04-11 17:51:58 +00:00
|
|
|
errG.Go(func() error {
|
|
|
|
raw, err := obj.Marshal()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("marshal: %v", err)
|
|
|
|
}
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err = st.Put(context.Background(), common.PutPrm{
|
2023-04-11 17:51:58 +00:00
|
|
|
Address: addr,
|
|
|
|
RawData: raw,
|
|
|
|
})
|
|
|
|
return err
|
|
|
|
})
|
2023-03-03 09:33:08 +00:00
|
|
|
}
|
2023-04-11 17:51:58 +00:00
|
|
|
require.NoError(b, errG.Wait())
|
2023-03-03 09:33:08 +00:00
|
|
|
|
|
|
|
// Benchmark reading
|
|
|
|
addrGen := tt.addrGen()
|
|
|
|
b.ResetTimer()
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
for pb.Next() {
|
2023-03-13 11:37:35 +00:00
|
|
|
_, err := st.Get(context.Background(), common.GetPrm{Address: addrGen.Next()})
|
2023-03-03 09:33:08 +00:00
|
|
|
require.NoError(b, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkSubstorageWritePerf(b *testing.B) {
|
|
|
|
generators := []struct {
|
|
|
|
desc string
|
2023-03-20 14:10:26 +00:00
|
|
|
create func() testutil.ObjectGenerator
|
2023-03-03 09:33:08 +00:00
|
|
|
}{
|
2023-03-20 14:10:26 +00:00
|
|
|
{desc: "rand10", create: func() testutil.ObjectGenerator { return &testutil.RandObjGenerator{ObjSize: 10} }},
|
|
|
|
{desc: "rand100", create: func() testutil.ObjectGenerator { return &testutil.RandObjGenerator{ObjSize: 100} }},
|
|
|
|
{desc: "rand1000", create: func() testutil.ObjectGenerator { return &testutil.RandObjGenerator{ObjSize: 1000} }},
|
|
|
|
{desc: "overwrite10", create: func() testutil.ObjectGenerator { return &testutil.OverwriteObjGenerator{ObjSize: 10, MaxObjects: 100} }},
|
|
|
|
{desc: "overwrite100", create: func() testutil.ObjectGenerator { return &testutil.OverwriteObjGenerator{ObjSize: 100, MaxObjects: 100} }},
|
|
|
|
{desc: "overwrite1000", create: func() testutil.ObjectGenerator {
|
|
|
|
return &testutil.OverwriteObjGenerator{ObjSize: 1000, MaxObjects: 100}
|
|
|
|
}},
|
2023-03-03 09:33:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, genEntry := range generators {
|
|
|
|
for _, stEntry := range storages {
|
|
|
|
b.Run(fmt.Sprintf("%s-%s", stEntry.desc, genEntry.desc), func(b *testing.B) {
|
|
|
|
gen := genEntry.create()
|
2023-04-11 17:20:32 +00:00
|
|
|
st := stEntry.open(b)
|
2024-10-21 13:27:28 +00:00
|
|
|
defer func() { require.NoError(b, st.Close(context.Background())) }()
|
2023-03-03 09:33:08 +00:00
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
for pb.Next() {
|
|
|
|
obj := gen.Next()
|
2023-03-28 14:16:03 +00:00
|
|
|
addr := testutil.AddressFromObject(b, obj)
|
2023-03-03 09:33:08 +00:00
|
|
|
raw, err := obj.Marshal()
|
|
|
|
require.NoError(b, err)
|
2023-04-12 14:01:29 +00:00
|
|
|
if _, err := st.Put(context.Background(), common.PutPrm{
|
2023-03-03 09:33:08 +00:00
|
|
|
Address: addr,
|
|
|
|
RawData: raw,
|
|
|
|
}); err != nil {
|
|
|
|
b.Fatalf("writing entry: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkSubstorageIteratePerf(b *testing.B) {
|
|
|
|
iterateTests := []struct {
|
|
|
|
desc string
|
|
|
|
size int
|
2023-03-20 14:10:26 +00:00
|
|
|
objGen func() testutil.ObjectGenerator
|
2023-03-03 09:33:08 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "rand100",
|
|
|
|
size: 10000,
|
2023-03-20 14:10:26 +00:00
|
|
|
objGen: func() testutil.ObjectGenerator { return &testutil.RandObjGenerator{ObjSize: 100} },
|
2023-03-03 09:33:08 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range iterateTests {
|
|
|
|
for _, stEntry := range storages {
|
|
|
|
b.Run(fmt.Sprintf("%s-%s", stEntry.desc, tt.desc), func(b *testing.B) {
|
|
|
|
objGen := tt.objGen()
|
2023-04-11 17:20:32 +00:00
|
|
|
st := stEntry.open(b)
|
2024-10-21 13:27:28 +00:00
|
|
|
defer func() { require.NoError(b, st.Close(context.Background())) }()
|
2023-03-03 09:33:08 +00:00
|
|
|
|
|
|
|
// Fill database
|
2024-08-30 16:20:55 +00:00
|
|
|
for range tt.size {
|
2023-03-03 09:33:08 +00:00
|
|
|
obj := objGen.Next()
|
2023-03-28 14:16:03 +00:00
|
|
|
addr := testutil.AddressFromObject(b, obj)
|
2023-03-03 09:33:08 +00:00
|
|
|
raw, err := obj.Marshal()
|
|
|
|
require.NoError(b, err)
|
2023-04-12 14:01:29 +00:00
|
|
|
if _, err := st.Put(context.Background(), common.PutPrm{
|
2023-03-03 09:33:08 +00:00
|
|
|
Address: addr,
|
|
|
|
RawData: raw,
|
|
|
|
}); err != nil {
|
|
|
|
b.Fatalf("writing entry: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Benchmark iterate
|
|
|
|
cnt := 0
|
|
|
|
b.ResetTimer()
|
2023-05-24 11:09:11 +00:00
|
|
|
_, err := st.Iterate(context.Background(), common.IteratePrm{
|
2023-03-03 09:33:08 +00:00
|
|
|
Handler: func(elem common.IterationElement) error {
|
|
|
|
cnt++
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(b, err)
|
|
|
|
require.Equal(b, tt.size, cnt)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|