[#674] storage engine: Use per-shard worker pools for PUT operation

Make `StorageEngine` to use non-blocking worker pools with the same
(configurable) size for PUT operation. This allows you to switch to using
more free shards when overloading others, thereby more evenly distributing
the write load.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-10-08 15:25:45 +03:00 committed by Alex Vanin
parent b08c6b3f30
commit 5b1975d52a
3 changed files with 73 additions and 36 deletions

View file

@ -4,6 +4,7 @@ import (
"sync"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
"github.com/nspcc-dev/neofs-node/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
"go.uber.org/zap"
)
@ -15,6 +16,8 @@ type StorageEngine struct {
mtx *sync.RWMutex
shards map[string]*shard.Shard
shardPools map[string]util.WorkerPool
}
// Option represents StorageEngine's constructor option.
@ -24,11 +27,15 @@ type cfg struct {
log *logger.Logger
metrics MetricRegister
shardPoolSize uint32
}
func defaultCfg() *cfg {
return &cfg{
log: zap.L(),
shardPoolSize: 20,
}
}
@ -41,9 +48,10 @@ func New(opts ...Option) *StorageEngine {
}
return &StorageEngine{
cfg: c,
mtx: new(sync.RWMutex),
shards: make(map[string]*shard.Shard),
cfg: c,
mtx: new(sync.RWMutex),
shards: make(map[string]*shard.Shard),
shardPools: make(map[string]util.WorkerPool),
}
}
@ -59,3 +67,10 @@ func WithMetrics(v MetricRegister) Option {
c.metrics = v
}
}
// WithShardPoolSize returns option to specify size of worker pool for each shard.
func WithShardPoolSize(sz uint32) Option {
return func(c *cfg) {
c.shardPoolSize = sz
}
}