services/tree: allow to customize some parameters

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-07-19 11:03:13 +03:00
parent 609dbe83db
commit 34d20fd592
6 changed files with 49 additions and 12 deletions

View file

@ -3,16 +3,21 @@ package main
import (
"context"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
"github.com/nspcc-dev/neofs-node/pkg/services/tree"
)
func initTreeService(c *cfg) {
sub := c.appCfg.Sub("tree")
c.treeService = tree.New(
tree.WithContainerSource(c.cfgObject.cnrSource),
tree.WithNetmapSource(c.netMapSource),
tree.WithPrivateKey(&c.key.PrivateKey),
tree.WithLogger(c.log),
tree.WithStorage(c.cfgObject.cfgLocalStorage.localStorage))
tree.WithStorage(c.cfgObject.cfgLocalStorage.localStorage),
tree.WithContainerCacheSize(int(config.IntSafe(sub, "cache_size"))),
tree.WithReplicationChannelCapacity(int(config.IntSafe(sub, "replication_channel_capacity"))),
tree.WithReplicationWorkerCount(int(config.IntSafe(sub, "replication_worker_count"))))
for _, srv := range c.cfgGRPC.servers {
tree.RegisterTreeServiceServer(srv, c.treeService)

View file

@ -60,6 +60,11 @@ grpc:
enabled: true
use_insecure_crypto: true # allow using insecure ciphers with TLS 1.2
tree:
cache_size: 10
replication_worker_count: 64
replication_channel_capacity: 64
control:
authorized_keys: # list of hex-encoded public keys that have rights to use the Control Service
- 035839e45d472a3b7769a2a1bd7d54c4ccd4943c3b40f547870e83a8fcbfb3ce11

View file

@ -19,8 +19,8 @@ type containerCache struct {
lru *simplelru.LRU
}
func (c *containerCache) init() {
c.lru, _ = simplelru.NewLRU(defaultContainerCacheSize, nil) // no error, size is positive
func (c *containerCache) init(size int) {
c.lru, _ = simplelru.NewLRU(size, nil) // no error, size is positive
}
type containerCacheItem struct {
@ -31,11 +31,6 @@ type containerCacheItem struct {
const defaultContainerCacheSize = 10
type index struct {
replica uint32
index uint32
}
// getContainerNodes returns nodes in the container and a position of local key in the list.
func (s *Service) getContainerNodes(cid cidSDK.ID) ([]netmapSDK.NodeInfo, int, error) {
nm, err := s.nmSource.GetNetMap(0)

View file

@ -17,6 +17,10 @@ type cfg struct {
nmSource netmap.Source
cnrSource container.Source
forest pilorama.Forest
// replication-related parameters
replicatorChannelCapacity int
replicatorWorkerCount int
containerCacheSize int
}
// Option represents configuration option for a tree service.
@ -60,3 +64,27 @@ func WithStorage(s pilorama.Forest) Option {
c.forest = s
}
}
func WithReplicationChannelCapacity(n int) Option {
return func(c *cfg) {
if n > 0 {
c.replicatorChannelCapacity = n
}
}
}
func WithReplicationWorkerCount(n int) Option {
return func(c *cfg) {
if n > 0 {
c.replicatorWorkerCount = n
}
}
}
func WithContainerCacheSize(n int) Option {
return func(c *cfg) {
if n > 0 {
c.containerCacheSize = n
}
}
}

View file

@ -66,7 +66,7 @@ func (s *Service) replicationWorker() {
}
func (s *Service) replicateLoop(ctx context.Context) {
for i := 0; i < defaultReplicatorWorkerCount; i++ {
for i := 0; i < s.replicatorWorkerCount; i++ {
go s.replicationWorker()
}
defer func() {

View file

@ -33,6 +33,10 @@ var _ TreeServiceServer = (*Service)(nil)
// New creates new tree service instance.
func New(opts ...Option) *Service {
var s Service
s.containerCacheSize = defaultContainerCacheSize
s.replicatorChannelCapacity = defaultReplicatorCapacity
s.replicatorWorkerCount = defaultReplicatorWorkerCount
for i := range opts {
opts[i](&s.cfg)
}
@ -43,9 +47,9 @@ func New(opts ...Option) *Service {
s.cache.init()
s.closeCh = make(chan struct{})
s.replicateCh = make(chan movePair, defaultReplicatorCapacity)
s.replicationTasks = make(chan replicationTask, defaultReplicatorWorkerCount)
s.containerCache.init()
s.replicateCh = make(chan movePair, s.replicatorChannelCapacity)
s.replicationTasks = make(chan replicationTask, s.replicatorWorkerCount)
s.containerCache.init(s.containerCacheSize)
return &s
}