diff --git a/cmd/neofs-node/tree.go b/cmd/neofs-node/tree.go index 12385a4f1..09c397ac4 100644 --- a/cmd/neofs-node/tree.go +++ b/cmd/neofs-node/tree.go @@ -8,7 +8,8 @@ import ( ) func initTreeService(c *cfg) { - if !config.BoolSafe(c.appCfg.Sub("tree"), "enabled") { + sub := c.appCfg.Sub("tree") + if !config.BoolSafe(sub, "enabled") { c.log.Info("tree service is not enabled, skip initialization") return } @@ -18,7 +19,10 @@ func initTreeService(c *cfg) { 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 46f3a9673..1921b1412 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -59,6 +59,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 5122a461e..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 { 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 }