Skip to content

Commit

Permalink
blobovnicza: Add benchmark to test different tree settings (#2457)
Browse files Browse the repository at this point in the history
current results:

BenchmarkBlobovniczas_Put/tree=1x0-8                 100          53517515 ns/op         4609697 B/op        109 allocs/op
BenchmarkBlobovniczas_Put/tree=10x0-8                100          53417156 ns/op         5213543 B/op        119 allocs/op
BenchmarkBlobovniczas_Put/tree=2x2-8                 100          52124287 ns/op         5117641 B/op        158 allocs/op
BenchmarkBlobovniczas_Put/tree=4x4-8                 100          37065895 ns/op         2129467 B/op        188 allocs/op
  • Loading branch information
roman-khimov authored Jul 26, 2023
2 parents 5987f59 + d22c757 commit 782f658
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions pkg/local_object_storage/blobstor/blobovniczatree/put_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package blobovniczatree_test

import (
"crypto/rand"
"errors"
"fmt"
"sync"
"testing"

. "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/blobovniczatree"
Expand Down Expand Up @@ -37,3 +41,84 @@ func TestSingleDir(t *testing.T) {
})
require.NoError(t, err)
}

func benchmarkPutMN(b *testing.B, depth, width uint64, parallel bool) {
nBlobovniczas := uint64(1)
for i := uint64(1); i <= depth+1; i++ {
nBlobovniczas *= width
}

const objSizeLimit = 4 << 10
const fullSizeLimit = 100 << 20

bbcz := NewBlobovniczaTree(
WithRootPath(b.TempDir()),
WithObjectSizeLimit(objSizeLimit),
WithBlobovniczaSize(fullSizeLimit/nBlobovniczas),
WithBlobovniczaShallowWidth(width),
WithBlobovniczaShallowDepth(depth),
)

require.NoError(b, bbcz.Open(false))
b.Cleanup(func() { _ = bbcz.Close() })
require.NoError(b, bbcz.Init())

prm := common.PutPrm{
RawData: make([]byte, objSizeLimit),
}

rand.Read(prm.RawData)

var wg sync.WaitGroup

f := func(prm common.PutPrm) {
defer wg.Done()

var err error

for i := 0; i < b.N; i++ {
prm.Address = oidtest.Address()

_, err = bbcz.Put(prm)
if err != nil {
if errors.Is(err, common.ErrNoSpace) {
break
}
require.NoError(b, err)
}
}
}

nRoutine := 1
if parallel {
nRoutine = 20
}

b.ReportAllocs()
b.ResetTimer()

for j := 0; j < nRoutine; j++ {
wg.Add(1)
go f(prm)
}

wg.Wait()
}

func BenchmarkBlobovniczas_Put(b *testing.B) {
for _, testCase := range []struct {
width, depth uint64
}{
{1, 0},
{10, 0},
{2, 2},
{4, 4},
} {
b.Run(fmt.Sprintf("tree=%dx%d", testCase.width, testCase.depth), func(b *testing.B) {
benchmarkPutMN(b, testCase.depth, testCase.width, false)
})
b.Run(fmt.Sprintf("tree=%dx%d_parallel", testCase.width, testCase.depth), func(b *testing.B) {
benchmarkPutMN(b, testCase.depth, testCase.width, true)
})
}
}

0 comments on commit 782f658

Please sign in to comment.