From 35a23234ca093b06b71ba4cdfaf73450de1d14a7 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 16 Feb 2021 18:10:20 +0200 Subject: [PATCH] lib/mergeset: tune lifetime for entries inside block caches This should reduce memory usage in general case without significant CPU usage increase --- lib/mergeset/part.go | 8 ++++---- lib/storage/part.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/mergeset/part.go b/lib/mergeset/part.go index 2b01d94bea..3bd4393994 100644 --- a/lib/mergeset/part.go +++ b/lib/mergeset/part.go @@ -221,8 +221,8 @@ func (idxbc *indexBlockCache) cleanByTimeout() { currentTime := fasttime.UnixTimestamp() idxbc.mu.Lock() for k, idxbe := range idxbc.m { - // Delete items accessed more than two minutes ago. - if currentTime-atomic.LoadUint64(&idxbe.lastAccessTime) > 2*60 { + // Delete items accessed more than 90 seconds ago. + if currentTime-atomic.LoadUint64(&idxbe.lastAccessTime) > 90 { // do not call putIndexBlock(ibxbc.m[k]), since it // may be used by concurrent goroutines. delete(idxbc.m, k) @@ -375,8 +375,8 @@ func (ibc *inmemoryBlockCache) cleanByTimeout() { currentTime := fasttime.UnixTimestamp() ibc.mu.Lock() for k, ibe := range ibc.m { - // Delete items accessed more than a two minutes ago. - if currentTime-atomic.LoadUint64(&ibe.lastAccessTime) > 2*60 { + // Delete items accessed more than 90 seconds ago. + if currentTime-atomic.LoadUint64(&ibe.lastAccessTime) > 90 { // do not call putInmemoryBlock(ibc.m[k]), since it // may be used by concurrent goroutines. delete(ibc.m, k) diff --git a/lib/storage/part.go b/lib/storage/part.go index 52b0ec41a9..e18fa0b973 100644 --- a/lib/storage/part.go +++ b/lib/storage/part.go @@ -225,8 +225,8 @@ func (ibc *indexBlockCache) cleanByTimeout() { currentTime := fasttime.UnixTimestamp() ibc.mu.Lock() for k, ibe := range ibc.m { - // Delete items accessed more than two minutes ago. - if currentTime-atomic.LoadUint64(&ibe.lastAccessTime) > 2*60 { + // Delete items accessed more than 90 seconds ago. + if currentTime-atomic.LoadUint64(&ibe.lastAccessTime) > 90 { delete(ibc.m, k) } }