[#1507] node: Do not handle object concurrently by the policer

Cache object that are being processed. That prevents concurrent
object handling when there is a few number of objects and object handling
takes more time that the policer needs for starting that object handling one
more time.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-06-09 19:45:51 +03:00 committed by LeL
parent 256165045b
commit 36f4929e52
3 changed files with 44 additions and 3 deletions

View file

@ -48,15 +48,24 @@ func (p *Policer) shardPolicyWorker(ctx context.Context) {
return
default:
addr := addrs[i]
addrStr := addr.EncodeToString()
if p.objsInWork.inWork(addr) {
// do not process an object
// that is in work
continue
}
err = p.taskPool.Submit(func() {
v, ok := p.cache.Get(addrStr)
v, ok := p.cache.Get(addr)
if ok && time.Since(v.(time.Time)) < p.evictDuration {
return
}
p.objsInWork.add(addr)
p.processObject(ctx, addr)
p.cache.Add(addrStr, time.Now())
p.cache.Add(addr, time.Now())
p.objsInWork.remove(addr)
})
if err != nil {
p.log.Warn("pool submission", zap.Error(err))