2023-04-26 11:23:33 +00:00
|
|
|
package pilorama
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
"sync/atomic"
|
|
|
|
"testing"
|
|
|
|
|
2024-02-09 06:17:17 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
2023-04-26 11:23:33 +00:00
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func getTimestamp(reorder int, ts Timestamp) Timestamp {
|
|
|
|
base := ts / Timestamp(reorder)
|
|
|
|
rem := ts % Timestamp(reorder)
|
|
|
|
return base*Timestamp(reorder) + Timestamp(reorder) - rem
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkCreate(b *testing.B) {
|
|
|
|
// Use `os.TempDir` because we construct multiple times in the same test.
|
|
|
|
tmpDir, err := os.MkdirTemp(os.TempDir(), "*")
|
|
|
|
require.NoError(b, err)
|
|
|
|
|
|
|
|
f := NewBoltForest(
|
|
|
|
WithPath(filepath.Join(tmpDir, "test.db")),
|
|
|
|
WithMaxBatchSize(runtime.GOMAXPROCS(0)))
|
2024-02-09 06:17:17 +00:00
|
|
|
require.NoError(b, f.Open(context.Background(), mode.ReadWrite))
|
2024-10-21 13:27:28 +00:00
|
|
|
require.NoError(b, f.Init(context.Background()))
|
|
|
|
defer func() { require.NoError(b, f.Close(context.Background())) }()
|
2024-01-09 13:26:43 +00:00
|
|
|
|
2023-04-26 11:23:33 +00:00
|
|
|
b.Cleanup(func() {
|
|
|
|
require.NoError(b, os.RemoveAll(tmpDir))
|
|
|
|
})
|
|
|
|
|
|
|
|
cid := cidtest.ID()
|
|
|
|
treeID := "tree"
|
|
|
|
ctx := context.Background()
|
|
|
|
var index atomic.Int32
|
|
|
|
index.Store(-1)
|
|
|
|
b.SetParallelism(2)
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
for pb.Next() {
|
|
|
|
i := index.Add(1)
|
|
|
|
op := &Move{
|
|
|
|
Meta: Meta{Time: getTimestamp(runtime.GOMAXPROCS(0)*2, Timestamp(i+1))},
|
|
|
|
Child: Node(i + 1),
|
|
|
|
Parent: RootID,
|
|
|
|
}
|
|
|
|
if err := f.TreeApply(ctx, cid, treeID, op, true); err != nil {
|
|
|
|
b.FailNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|