From 34d20fd592f24d7b16fc4b119ad7675d6e01baf7 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 19 Jul 2022 11:03:13 +0300 Subject: [PATCH] services/tree: allow to customize some parameters Signed-off-by: Evgenii Stratonikov --- cmd/neofs-node/tree.go | 7 ++++++- config/example/node.yaml | 5 +++++ pkg/services/tree/container.go | 9 ++------- pkg/services/tree/options.go | 28 ++++++++++++++++++++++++++++ pkg/services/tree/replicator.go | 2 +- pkg/services/tree/service.go | 10 +++++++--- 6 files changed, 49 insertions(+), 12 deletions(-) diff --git a/cmd/neofs-node/tree.go b/cmd/neofs-node/tree.go index 4be5ac093..a26f3fb06 100644 --- a/cmd/neofs-node/tree.go +++ b/cmd/neofs-node/tree.go @@ -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) diff --git a/config/example/node.yaml b/config/example/node.yaml index 29c8cb5d0..b7bd3f0b8 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -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 diff --git a/pkg/services/tree/container.go b/pkg/services/tree/container.go index 1e950ffc1..525fdde58 100644 --- a/pkg/services/tree/container.go +++ b/pkg/services/tree/container.go @@ -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) diff --git a/pkg/services/tree/options.go b/pkg/services/tree/options.go index 59917ec93..2ee8eb4ed 100644 --- a/pkg/services/tree/options.go +++ b/pkg/services/tree/options.go @@ -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 + } + } +} diff --git a/pkg/services/tree/replicator.go b/pkg/services/tree/replicator.go index afbdbeee8..0fc0271bd 100644 --- a/pkg/services/tree/replicator.go +++ b/pkg/services/tree/replicator.go @@ -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() { diff --git a/pkg/services/tree/service.go b/pkg/services/tree/service.go index b344c1393..9b6b5e544 100644 --- a/pkg/services/tree/service.go +++ b/pkg/services/tree/service.go @@ -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 }