lib/storage: reset perKeyMisses stats less frequently

This should reduce CPU usage for queries executed with intervals higher than 30 seconds
This commit is contained in:
Aliaksandr Valialkin 2021-07-12 14:33:39 +03:00
parent 3f705fe8d7
commit 51cd19d2e3

View file

@ -196,10 +196,16 @@ func (idxbc *indexBlockCache) MustClose() {
func (idxbc *indexBlockCache) cleaner() {
ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()
perKeyMissesTicker := time.NewTicker(2 * time.Minute)
defer perKeyMissesTicker.Stop()
for {
select {
case <-ticker.C:
idxbc.cleanByTimeout()
case <-perKeyMissesTicker.C:
idxbc.perKeyMissesLock.Lock()
idxbc.perKeyMisses = make(map[uint64]int, len(idxbc.perKeyMisses))
idxbc.perKeyMissesLock.Unlock()
case <-idxbc.cleanerStopCh:
return
}
@ -217,10 +223,6 @@ func (idxbc *indexBlockCache) cleanByTimeout() {
}
}
idxbc.mu.Unlock()
idxbc.perKeyMissesLock.Lock()
idxbc.perKeyMisses = make(map[uint64]int, len(idxbc.perKeyMisses))
idxbc.perKeyMissesLock.Unlock()
}
func (idxbc *indexBlockCache) Get(k uint64) *indexBlock {
@ -360,10 +362,16 @@ func (ibc *inmemoryBlockCache) MustClose() {
func (ibc *inmemoryBlockCache) cleaner() {
ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()
perKeyMissesTicker := time.NewTicker(2 * time.Minute)
defer perKeyMissesTicker.Stop()
for {
select {
case <-ticker.C:
ibc.cleanByTimeout()
case <-perKeyMissesTicker.C:
ibc.perKeyMissesLock.Lock()
ibc.perKeyMisses = make(map[inmemoryBlockCacheKey]int, len(ibc.perKeyMisses))
ibc.perKeyMissesLock.Unlock()
case <-ibc.cleanerStopCh:
return
}
@ -381,10 +389,6 @@ func (ibc *inmemoryBlockCache) cleanByTimeout() {
}
}
ibc.mu.Unlock()
ibc.perKeyMissesLock.Lock()
ibc.perKeyMisses = make(map[inmemoryBlockCacheKey]int, len(ibc.perKeyMisses))
ibc.perKeyMissesLock.Unlock()
}
func (ibc *inmemoryBlockCache) Get(k inmemoryBlockCacheKey) *inmemoryBlock {