2022-05-24 12:06:29 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
2023-03-07 13:38:26 +00:00
|
|
|
"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"
|
2022-05-24 12:06:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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) {
|
|
|
|
e, _, _ := newEngineWithErrorThreshold(b, "", 0)
|
|
|
|
cid := cidtest.ID()
|
2022-05-27 12:55:02 +00:00
|
|
|
d := pilorama.CIDDescriptor{CID: cid, Position: 0, Size: 1}
|
2022-05-24 12:06:29 +00:00
|
|
|
treeID := "someTree"
|
|
|
|
|
|
|
|
for i := 0; i < objCount; i++ {
|
2023-03-20 14:10:26 +00:00
|
|
|
obj := testutil.GenerateObjectWithCID(cid)
|
|
|
|
testutil.AddAttribute(obj, pilorama.AttributeFilename, strconv.Itoa(i))
|
2022-05-24 12:06:29 +00:00
|
|
|
err := Put(e, obj)
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
2022-05-27 12:55:02 +00:00
|
|
|
_, err = e.TreeAddByPath(d, treeID, pilorama.AttributeFilename, nil,
|
2022-05-24 12:06:29 +00:00
|
|
|
[]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 := e.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 := e.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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|