forked from TrueCloudLab/frostfs-node
[#674] node: Configure size of per-shard worker pools
Add `shard_pool_size` config to `storage` section. Set app default to 20. Pass the value to `WithShardPoolSize` option. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
5b1975d52a
commit
2126235f0e
6 changed files with 35 additions and 3 deletions
|
@ -7,13 +7,21 @@ import (
|
|||
shardconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard"
|
||||
)
|
||||
|
||||
const (
|
||||
subsection = "storage"
|
||||
|
||||
// ShardPoolSizeDefault is a default value of routine pool size per-shard to
|
||||
// process object PUT operations in storage engine.
|
||||
ShardPoolSizeDefault = 20
|
||||
)
|
||||
|
||||
// IterateShards iterates over subsections ["0":"N") (N - "shard_num" value)
|
||||
// of "shard" subsection of "storage" section of c, wrap them into
|
||||
// shardconfig.Config and passes to f.
|
||||
//
|
||||
// Panics if N is not a positive number.
|
||||
func IterateShards(c *config.Config, f func(*shardconfig.Config)) {
|
||||
c = c.Sub("storage")
|
||||
c = c.Sub(subsection)
|
||||
|
||||
num := config.Uint(c, "shard_num")
|
||||
if num == 0 {
|
||||
|
@ -32,3 +40,15 @@ func IterateShards(c *config.Config, f func(*shardconfig.Config)) {
|
|||
f(sc)
|
||||
}
|
||||
}
|
||||
|
||||
// ShardPoolSize returns value of "shard_pool_size" config parameter from "storage" section.
|
||||
//
|
||||
// Returns ShardPoolSizeDefault if value is not a positive number.
|
||||
func ShardPoolSize(c *config.Config) uint32 {
|
||||
v := config.Uint32Safe(c.Sub(subsection), "shard_pool_size")
|
||||
if v > 0 {
|
||||
return v
|
||||
}
|
||||
|
||||
return ShardPoolSizeDefault
|
||||
}
|
||||
|
|
|
@ -14,9 +14,13 @@ import (
|
|||
|
||||
func TestEngineSection(t *testing.T) {
|
||||
t.Run("defaults", func(t *testing.T) {
|
||||
empty := configtest.EmptyConfig()
|
||||
|
||||
require.Panics(t, func() {
|
||||
engineconfig.IterateShards(configtest.EmptyConfig(), nil)
|
||||
engineconfig.IterateShards(empty, nil)
|
||||
})
|
||||
|
||||
require.EqualValues(t, engineconfig.ShardPoolSizeDefault, engineconfig.ShardPoolSize(empty))
|
||||
})
|
||||
|
||||
const path = "../../../../config/example/node"
|
||||
|
@ -24,6 +28,8 @@ func TestEngineSection(t *testing.T) {
|
|||
var fileConfigTest = func(c *config.Config) {
|
||||
num := 0
|
||||
|
||||
require.EqualValues(t, 15, engineconfig.ShardPoolSize(c))
|
||||
|
||||
engineconfig.IterateShards(c, func(sc *shardconfig.Config) {
|
||||
defer func() {
|
||||
num++
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue