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 d906d8573e
This commit is contained in:
Aliaksandr Valialkin 2022-11-10 12:01:02 +02:00
parent 5ff6e0fb02
commit 71335e6024
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1

View File

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