Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis caches - when can large evictions be triggered?

We have a Redis Cache on Azure Standard 2.5gb. We observe the following behaviour:

enter image description here

Every now and then, we observe large drops in memory usage. It appears that lots of resources are being evicted.

Things to note:

  • Eviction policy is LRU
  • Available cache size is 2.5gb
  • No application code that would evict such large amounts of memory (largest objects are ~80kb and most are significantly smaller)
  • Observed memory drops represent tens of thousands of keys
  • We seldom use explicit expiry dates on cached objects, and when we do they are always < 1 hour.

My question is, apart from application logic explicitly evicting keys are there any other circumstances Redis would evict large amounts of keys?

like image 979
Tom Gullen Avatar asked Dec 03 '18 15:12

Tom Gullen


People also ask

What causes cache eviction?

Cache eviction is a feature where file data blocks in the cache are released when fileset usage exceeds the fileset soft quota, and space is created for new files. The process of releasing blocks is called eviction. However, file data is not evicted if the file data is dirty.

What happens when Redis cache is full?

If this limit is reached Redis will start to reply with an error to write commands (but will continue to accept read-only commands), or you can configure it to evict keys when the max memory limit is reached in the case you are using Redis for caching.

How does Redis eviction policy?

Eviction policy The default policy for Azure Cache for Redis is volatile-lru , which means that only keys that have a TTL value set with a command like EXPIRE are eligible for eviction. If no keys have a TTL value, then the system won't evict any keys.

What are Redis evictions?

Evictions occur when cache memory is overfilled or is greater than the maxmemory setting for the cache, causing the engine to select keys to evict to manage its memory. The keys that are chosen are based on the eviction policy you select.


1 Answers

The memory cleanup may not represent evictions.

You say "it appears" that lots of resources are being evicted, but if you are just relying on the reclaimed memory for that appearance, you may be chasing ghosts. Have you checked how this graph overlays with the Total Keys metric available in the Azure Portal? Overlaying the two series should allow you to see whether or not the memory reclamation really is due to eviction or if it's due to another process like Azure perhaps calling MEMORY PURGE periodically on the cache instance to clean up dirty pages?

like image 122
Dusty Avatar answered Sep 28 '22 04:09

Dusty