From 504f45e9ee13f38cee96451a2467c583a5f8e090 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 14 Jun 2022 18:21:29 +0300 Subject: [PATCH] [#1516] metabase: Add benchmark for `ListWithCursor` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` name time/op ListWithCursor/1_item-8 10.6µs ± 1% ListWithCursor/10_items-8 75.3µs ± 2% ListWithCursor/100_items-8 726µs ± 2% name alloc/op ListWithCursor/1_item-8 3.19kB ± 0% ListWithCursor/10_items-8 20.7kB ± 0% ListWithCursor/100_items-8 196kB ± 0% name allocs/op ListWithCursor/1_item-8 55.0 ± 0% ListWithCursor/10_items-8 346 ± 0% ListWithCursor/100_items-8 3.25k ± 0% ``` Signed-off-by: Evgenii Stratonikov --- .../metabase/list_test.go | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/pkg/local_object_storage/metabase/list_test.go b/pkg/local_object_storage/metabase/list_test.go index a731bda74..a6170bf3a 100644 --- a/pkg/local_object_storage/metabase/list_test.go +++ b/pkg/local_object_storage/metabase/list_test.go @@ -10,9 +10,61 @@ import ( cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" + oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" + "go.etcd.io/bbolt" ) +func BenchmarkListWithCursor(b *testing.B) { + db := listWithCursorPrepareDB(b) + b.Run("1 item", func(b *testing.B) { + benchmarkListWithCursor(b, db, 1) + }) + b.Run("10 items", func(b *testing.B) { + benchmarkListWithCursor(b, db, 10) + }) + b.Run("100 items", func(b *testing.B) { + benchmarkListWithCursor(b, db, 100) + }) +} + +func listWithCursorPrepareDB(b *testing.B) *meta.DB { + db := newDB(b, meta.WithBatchSize(1), meta.WithBoltDBOptions(&bbolt.Options{ + NoSync: true, + })) // faster single-thread generation + + obj := generateObject(b) + for i := 0; i < 100_000; i++ { // should be a multiple of all batch sizes + obj.SetID(oidtest.ID()) + if i%9 == 0 { // let's have 9 objects per container + obj.SetContainerID(cidtest.ID()) + } + require.NoError(b, putBig(db, obj)) + } + return db +} + +func benchmarkListWithCursor(b *testing.B, db *meta.DB, batchSize int) { + var prm meta.ListPrm + prm.WithCount(uint32(batchSize)) + + b.ResetTimer() + b.ReportAllocs() + for i := 0; i < b.N; i++ { + res, err := db.ListWithCursor(prm) + if err != nil { + if err != meta.ErrEndOfListing { + b.Fatalf("error: %v", err) + } + prm.WithCursor(nil) + } else if ln := len(res.AddressList()); ln != batchSize { + b.Fatalf("invalid batch size: %d", ln) + } else { + prm.WithCursor(res.Cursor()) + } + } +} + func TestLisObjectsWithCursor(t *testing.T) { db := newDB(t)