From 07e06249d52307df9cc4a11d6be1d27a408d7598 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 15 Jun 2022 09:59:51 +0300 Subject: [PATCH] [#1524] metabase: Add some bolt parameters to the configuration Signed-off-by: Evgenii Stratonikov --- cmd/neofs-node/config.go | 2 ++ cmd/neofs-node/config/engine/config_test.go | 4 ++++ config/example/node.env | 4 ++++ config/example/node.json | 8 ++++++-- config/example/node.yaml | 4 ++++ pkg/local_object_storage/metabase/db.go | 16 ++++++++++------ pkg/local_object_storage/metabase/list_test.go | 2 +- pkg/local_object_storage/metabase/put_test.go | 8 ++++---- 8 files changed, 35 insertions(+), 13 deletions(-) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index f6387980..dd7f1bdd 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -445,6 +445,8 @@ func initShardOptions(c *cfg) { meta.WithLogger(c.log), meta.WithPath(metaPath), meta.WithPermissions(metaPerm), + meta.WithMaxBatchSize(metabaseCfg.BoltDB().MaxBatchSize()), + meta.WithMaxBatchDelay(metabaseCfg.BoltDB().MaxBatchDelay()), meta.WithBoltDBOptions(&bbolt.Options{ Timeout: 100 * time.Millisecond, }), diff --git a/cmd/neofs-node/config/engine/config_test.go b/cmd/neofs-node/config/engine/config_test.go index a7476b6c..59a7dbbd 100644 --- a/cmd/neofs-node/config/engine/config_test.go +++ b/cmd/neofs-node/config/engine/config_test.go @@ -68,6 +68,8 @@ func TestEngineSection(t *testing.T) { require.Equal(t, "tmp/0/meta", meta.Path()) require.Equal(t, fs.FileMode(0644), meta.BoltDB().Perm()) + require.Equal(t, 100, meta.BoltDB().MaxBatchSize()) + require.Equal(t, 10*time.Millisecond, meta.BoltDB().MaxBatchDelay()) require.Equal(t, "tmp/0/blob", blob.Path()) require.EqualValues(t, 0644, blob.Perm()) @@ -98,6 +100,8 @@ func TestEngineSection(t *testing.T) { require.Equal(t, "tmp/1/meta", meta.Path()) require.Equal(t, fs.FileMode(0644), meta.BoltDB().Perm()) + require.Equal(t, 200, meta.BoltDB().MaxBatchSize()) + require.Equal(t, 20*time.Millisecond, meta.BoltDB().MaxBatchDelay()) require.Equal(t, "tmp/1/blob", blob.Path()) require.EqualValues(t, 0644, blob.Perm()) diff --git a/config/example/node.env b/config/example/node.env index 5ce451cb..ff728166 100644 --- a/config/example/node.env +++ b/config/example/node.env @@ -91,6 +91,8 @@ NEOFS_STORAGE_SHARD_0_WRITECACHE_CAPACITY=3221225472 ### Metabase config NEOFS_STORAGE_SHARD_0_METABASE_PATH=tmp/0/meta NEOFS_STORAGE_SHARD_0_METABASE_PERM=0644 +NEOFS_STORAGE_SHARD_0_METABASE_MAX_BATCH_SIZE=100 +NEOFS_STORAGE_SHARD_0_METABASE_MAX_BATCH_DELAY=10ms ### Blobstor config NEOFS_STORAGE_SHARD_0_BLOBSTOR_PATH=tmp/0/blob NEOFS_STORAGE_SHARD_0_BLOBSTOR_PERM=0644 @@ -125,6 +127,8 @@ NEOFS_STORAGE_SHARD_1_WRITECACHE_CAPACITY=4294967296 ### Metabase config NEOFS_STORAGE_SHARD_1_METABASE_PATH=tmp/1/meta NEOFS_STORAGE_SHARD_1_METABASE_PERM=0644 +NEOFS_STORAGE_SHARD_1_METABASE_MAX_BATCH_SIZE=200 +NEOFS_STORAGE_SHARD_1_METABASE_MAX_BATCH_DELAY=20ms ### Blobstor config NEOFS_STORAGE_SHARD_1_BLOBSTOR_PATH=tmp/1/blob NEOFS_STORAGE_SHARD_1_BLOBSTOR_PERM=0644 diff --git a/config/example/node.json b/config/example/node.json index 114fe831..d1a878b9 100644 --- a/config/example/node.json +++ b/config/example/node.json @@ -136,7 +136,9 @@ }, "metabase": { "path": "tmp/0/meta", - "perm": "0644" + "perm": "0644", + "max_batch_size": 100, + "max_batch_delay": "10ms" }, "blobstor": { "path": "tmp/0/blob", @@ -173,7 +175,9 @@ }, "metabase": { "path": "tmp/1/meta", - "perm": "0644" + "perm": "0644", + "max_batch_size": 200, + "max_batch_delay": "20ms" }, "blobstor": { "path": "tmp/1/blob", diff --git a/config/example/node.yaml b/config/example/node.yaml index 797d0855..7440d797 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -116,6 +116,8 @@ storage: metabase: perm: 0644 # permissions for metabase files(directories: +x for current user and group) + max_batch_size: 200 + max_batch_delay: 20ms blobstor: compress: false # turn on/off zstd(level 3) compression of stored objects @@ -145,6 +147,8 @@ storage: metabase: path: tmp/0/meta # metabase path + max_batch_size: 100 + max_batch_delay: 10ms blobstor: path: tmp/0/blob # blobstor path diff --git a/pkg/local_object_storage/metabase/db.go b/pkg/local_object_storage/metabase/db.go index bd113027..3143ded1 100644 --- a/pkg/local_object_storage/metabase/db.go +++ b/pkg/local_object_storage/metabase/db.go @@ -278,20 +278,24 @@ func WithPermissions(perm fs.FileMode) Option { } } -// WithBatchSize returns option to specify maximum concurrent operations +// WithMaxBatchSize returns option to specify maximum concurrent operations // to be processed in a single transactions. // This option is missing from `bbolt.Options` but is set right after DB is open. -func WithBatchSize(s int) Option { +func WithMaxBatchSize(s int) Option { return func(c *cfg) { - c.boltBatchSize = s + if s != 0 { + c.boltBatchSize = s + } } } -// WithBatchDelay returns option to specify maximum time to wait before +// WithMaxBatchDelay returns option to specify maximum time to wait before // the batch of concurrent transactions is processed. // This option is missing from `bbolt.Options` but is set right after DB is open. -func WithBatchDelay(d time.Duration) Option { +func WithMaxBatchDelay(d time.Duration) Option { return func(c *cfg) { - c.boltBatchDelay = d + if d != 0 { + c.boltBatchDelay = d + } } } diff --git a/pkg/local_object_storage/metabase/list_test.go b/pkg/local_object_storage/metabase/list_test.go index a6170bf3..6cf5814a 100644 --- a/pkg/local_object_storage/metabase/list_test.go +++ b/pkg/local_object_storage/metabase/list_test.go @@ -29,7 +29,7 @@ func BenchmarkListWithCursor(b *testing.B) { } func listWithCursorPrepareDB(b *testing.B) *meta.DB { - db := newDB(b, meta.WithBatchSize(1), meta.WithBoltDBOptions(&bbolt.Options{ + db := newDB(b, meta.WithMaxBatchSize(1), meta.WithBoltDBOptions(&bbolt.Options{ NoSync: true, })) // faster single-thread generation diff --git a/pkg/local_object_storage/metabase/put_test.go b/pkg/local_object_storage/metabase/put_test.go index c0194aa1..d02b2a48 100644 --- a/pkg/local_object_storage/metabase/put_test.go +++ b/pkg/local_object_storage/metabase/put_test.go @@ -43,8 +43,8 @@ func prepareObjects(t testing.TB, n int) []*objectSDK.Object { func BenchmarkPut(b *testing.B) { b.Run("parallel", func(b *testing.B) { db := newDB(b, - meta.WithBatchDelay(time.Millisecond*10), - meta.WithBatchSize(runtime.NumCPU())) + meta.WithMaxBatchDelay(time.Millisecond*10), + meta.WithMaxBatchSize(runtime.NumCPU())) // Ensure the benchmark is bound by CPU and not waiting batch-delay time. b.SetParallelism(1) @@ -62,8 +62,8 @@ func BenchmarkPut(b *testing.B) { }) b.Run("sequential", func(b *testing.B) { db := newDB(b, - meta.WithBatchDelay(time.Millisecond*10), - meta.WithBatchSize(1)) + meta.WithMaxBatchDelay(time.Millisecond*10), + meta.WithMaxBatchSize(1)) index := atomic.NewInt64(-1) objs := prepareObjects(b, b.N) b.ResetTimer()