2022-05-24 12:06:29 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
2022-05-24 12:06:29 +00:00
|
|
|
"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"
|
2023-07-06 12:36:41 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2024-01-18 19:24:34 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
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) {
|
2023-03-21 10:38:44 +00:00
|
|
|
te := newEngineWithErrorThreshold(b, "", 0)
|
2024-01-18 19:24:34 +00:00
|
|
|
defer func() {
|
|
|
|
require.NoError(b, te.ng.Close(context.Background()))
|
|
|
|
}()
|
|
|
|
|
2022-05-24 12:06:29 +00:00
|
|
|
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"
|
|
|
|
|
2024-08-30 16:20:55 +00:00
|
|
|
for i := range objCount {
|
2023-03-20 14:10:26 +00:00
|
|
|
obj := testutil.GenerateObjectWithCID(cid)
|
|
|
|
testutil.AddAttribute(obj, pilorama.AttributeFilename, strconv.Itoa(i))
|
2024-10-01 12:27:06 +00:00
|
|
|
err := Put(context.Background(), te.ng, obj, false)
|
2022-05-24 12:06:29 +00:00
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
2023-04-13 12:36:20 +00:00
|
|
|
_, err = te.ng.TreeAddByPath(context.Background(), d, treeID, pilorama.AttributeFilename, nil,
|
2023-06-22 07:50:06 +00:00
|
|
|
[]pilorama.KeyValue{{Key: pilorama.AttributeFilename, Value: []byte(strconv.Itoa(i))}})
|
2022-05-24 12:06:29 +00:00
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
b.Run("search", func(b *testing.B) {
|
|
|
|
var prm SelectPrm
|
2024-10-02 11:52:54 +00:00
|
|
|
prm.WithContainerID(cid, true)
|
2022-05-24 12:06:29 +00:00
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
var fs objectSDK.SearchFilters
|
|
|
|
fs.AddFilter(pilorama.AttributeFilename, strconv.Itoa(objCount/2), objectSDK.MatchStringEqual)
|
2022-05-24 12:06:29 +00:00
|
|
|
prm.WithFilters(fs)
|
|
|
|
|
2024-08-30 16:20:55 +00:00
|
|
|
for range b.N {
|
2023-04-12 14:01:29 +00:00
|
|
|
res, err := te.ng.Select(context.Background(), prm)
|
2022-05-24 12:06:29 +00:00
|
|
|
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) {
|
2024-08-30 16:20:55 +00:00
|
|
|
for range b.N {
|
2023-04-13 12:36:20 +00:00
|
|
|
nodes, err := te.ng.TreeGetByPath(context.Background(), cid, treeID, pilorama.AttributeFilename, []string{strconv.Itoa(objCount / 2)}, true)
|
2022-05-24 12:06:29 +00:00
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
if count := len(nodes); count != 1 {
|
|
|
|
b.Fatalf("expected 1 object, got %d", count)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|