From 71335e6024831408f79d3d086a7cbfb8ebd670e5 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 10 Nov 2022 12:01:02 +0200 Subject: [PATCH] lib/workingsetcache: tune cache miss threshold for resetting the previous cache from 5% to 1% It has been appeared that some production workloads could suffer for some time after every reset of the previous cache when it gets less than 5% of requests after the needed item isn't found in the current cache. This could result in reduced cache hit rates, which, in turn, could increase CPU, disk IO and RAM usage needed for reading, unpacking and caching the missed data from disk. This commit reduces the cache miss threshold for resetting the previous cache from 5% to 1%. This should reduce the possible negative impact after each cache reset by at least 5x, while reducing the total memory used by caches. This is a follow-up for d906d8573ee373393d2f5d4223b7b372952c5be7 --- lib/workingsetcache/cache.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/workingsetcache/cache.go b/lib/workingsetcache/cache.go index e341cc385c..84a7d436b6 100644 --- a/lib/workingsetcache/cache.go +++ b/lib/workingsetcache/cache.go @@ -164,7 +164,7 @@ func (c *Cache) expirationWatcher(expireDuration time.Duration) { func (c *Cache) prevCacheWatcher() { // Watch for the usage of the prev cache and drop it whenever it receives - // less than 5% of requests comparing to the curr cache during the last 10 seconds. + // less than 1% of requests comparing to the curr cache during the last 10 seconds. checkInterval := 10 * time.Second checkInterval += timeJitter(checkInterval / 10) t := time.NewTicker(checkInterval) @@ -198,7 +198,7 @@ func (c *Cache) prevCacheWatcher() { } currGetCalls = csCurr.GetCalls prevGetCalls = csPrev.GetCalls - if currRequests >= 20 && float64(prevRequests)/float64(currRequests) < 0.05 { + if currRequests >= 100 && float64(prevRequests)/float64(currRequests) < 0.01 { // The majority of requests are served from the curr cache, // so the prev cache can be deleted in order to free up memory. if csPrev.EntriesCount > 0 {