frostfs-node/pkg/local_object_storage/engine/tree_test.go
Alexander Chuprov 033eaf77e1
All checks were successful
Build / Build Components (1.20) (pull_request) Successful in 3m52s
Build / Build Components (1.19) (pull_request) Successful in 4m1s
ci/woodpecker/pr/pre-commit Pipeline was successful
Tests and linters / Tests with -race (pull_request) Successful in 5m36s
Tests and linters / Tests (1.20) (pull_request) Successful in 5m55s
Tests and linters / Lint (pull_request) Successful in 14m40s
Tests and linters / Tests (1.19) (pull_request) Successful in 15m29s
ci/woodpecker/push/pre-commit Pipeline was successful
[#496] node: Fix linter importas
Standardize the alias of the
import frostfs-sdk-go/object as objectSDK.

Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
2023-07-06 15:36:41 +03:00

75 lines
2.1 KiB
Go

package engine
import (
"context"
"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"
objectSDK "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(context.Background(), te.ng, obj)
if err != nil {
b.Fatal(err)
}
_, err = te.ng.TreeAddByPath(context.Background(), d, treeID, pilorama.AttributeFilename, nil,
[]pilorama.KeyValue{{Key: pilorama.AttributeFilename, Value: []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 objectSDK.SearchFilters
fs.AddFilter(pilorama.AttributeFilename, strconv.Itoa(objCount/2), objectSDK.MatchStringEqual)
prm.WithFilters(fs)
for i := 0; i < b.N; i++ {
res, err := te.ng.Select(context.Background(), 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(context.Background(), 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)
}
}
})
}