[#1607] 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 committed by fyrchik
parent 2334e94fdb
commit b549cc314c
6 changed files with 49 additions and 8 deletions

View file

@ -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)

View file

@ -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

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 {

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
}