Alejandro Lopez
341fe1688f
All checks were successful
ci/woodpecker/push/pre-commit Pipeline was successful
This aims to reduce the usage of chmod hackery to induce or simulate OS-related failures. Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
74 lines
2 KiB
Go
74 lines
2 KiB
Go
package engine
|
|
|
|
import (
|
|
"strconv"
|
|
"testing"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama"
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
)
|
|
|
|
func BenchmarkTreeVsSearch(b *testing.B) {
|
|
b.Run("10 objects", func(b *testing.B) {
|
|
benchmarkTreeVsSearch(b, 10)
|
|
})
|
|
b.Run("100 objects", func(b *testing.B) {
|
|
benchmarkTreeVsSearch(b, 100)
|
|
})
|
|
b.Run("1000 objects", func(b *testing.B) {
|
|
benchmarkTreeVsSearch(b, 1000)
|
|
})
|
|
}
|
|
|
|
func benchmarkTreeVsSearch(b *testing.B, objCount int) {
|
|
te := newEngineWithErrorThreshold(b, "", 0)
|
|
cid := cidtest.ID()
|
|
d := pilorama.CIDDescriptor{CID: cid, Position: 0, Size: 1}
|
|
treeID := "someTree"
|
|
|
|
for i := 0; i < objCount; i++ {
|
|
obj := testutil.GenerateObjectWithCID(cid)
|
|
testutil.AddAttribute(obj, pilorama.AttributeFilename, strconv.Itoa(i))
|
|
err := Put(te.ng, obj)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
_, err = te.ng.TreeAddByPath(d, treeID, pilorama.AttributeFilename, nil,
|
|
[]pilorama.KeyValue{{pilorama.AttributeFilename, []byte(strconv.Itoa(i))}})
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
|
|
b.Run("search", func(b *testing.B) {
|
|
var prm SelectPrm
|
|
prm.WithContainerID(cid)
|
|
|
|
var fs object.SearchFilters
|
|
fs.AddFilter(pilorama.AttributeFilename, strconv.Itoa(objCount/2), object.MatchStringEqual)
|
|
prm.WithFilters(fs)
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
res, err := te.ng.Select(prm)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
if count := len(res.addrList); count != 1 {
|
|
b.Fatalf("expected 1 object, got %d", count)
|
|
}
|
|
}
|
|
})
|
|
b.Run("TreeGetByPath", func(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
nodes, err := te.ng.TreeGetByPath(cid, treeID, pilorama.AttributeFilename, []string{strconv.Itoa(objCount / 2)}, true)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
if count := len(nodes); count != 1 {
|
|
b.Fatalf("expected 1 object, got %d", count)
|
|
}
|
|
}
|
|
})
|
|
}
|