Redis on AWS Elasticache OOM error and 'maxmemory-policy'

Redis on AWS Elasticache OOM error and 'maxmemory-policy'

by Andrew Zito -
Number of replies: 0

We have a Moodle staging environment (3.7.1) set up on AWS using ElastiCache Redis. One morning, I was greeted by an error: "OOM command not allowed". Here is a comprehensive article from AWS describing this error and the underlying cause:https://aws.amazon.com/premiumsupport/knowledge-center/oom-command-not-allowed-redis/

To summarize, there is a property of the cache called maxmemory-policy, which determines which keys get deleted when space needs to be freed up. The default value, volatile-lru, will only ever delete keys which have a TTL set; however, neither we nor Moodle set TTLs on any of the keys, causing the cache tofill to the brim and eventually run out of space.

We've confirmed that one way to fix is to use a different maxmemory-policy: allkeys-lru. Both volatile-lru and allkeys-lru delete least recently used keys first, but `volatile` only acts on keys with TTLs.

There is a comment in the Moodle Redis driver (cache/store/redis/lib.php) which reads:

/**
 * Redis Cache Store
 *
 * To allow separation of definitions in Moodle and faster purging, each cache
 * is implemented as a Redis hash.  That is a trade-off between having functionality of TTL
 * and being able to manage many caches in a single redis instance.  Given the recommendation
 * not to use TTL if at all possible and the benefits of having many stores in Redis using the
 * hash configuration, the hash implementation has been used.
 *
 * @copyright   2013 Adam Durana
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
Does anyone have any thoughts on the correct way to resolve this OOM error? Is our solution sufficient/does it have downsides? Why is it recommended not to use TTLs? Any thoughts the community can share are greatly appreciated.

Average of ratings: Useful (2)