volatile-ttl evicts non-expired keys?

315 views
Skip to first unread message

Aditya Sanghi

unread,
Sep 25, 2018, 4:40:24 PM9/25/18
to Redis DB
Hello Redis folks,

If we use `volatile-ttl` as an eviction policy, could redis potentially evict keys which have expired set but not yet expired? e.g. if a key has expiry set for 1 year ahead but it is not yet 1 year (ie key is still live), could that key be a candidate for eviction? 

Cheers,
Aditya

Itamar Haber

unread,
Sep 25, 2018, 4:48:00 PM9/25/18
to Redis DB
Hello Aditya,

What you're describing is an exact match with the docs (https://redis.io/topics/lru-cache#eviction-policies):

volatile-ttl: evict keys with an expire set, and try to evict keys with a shorter time to live (TTL) first, in order to make space for the new data added.

Note the use of "try to evict" - Redis employs sampling to pick candidates for eviction, which provides a way to balance between being absolutely correct and performing well.

Cheers,

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.


--

Itamar Haber
Technicalist Evangenly

Phone: +972.54.567.9692

Redis Labs


Aditya Sanghi

unread,
Sep 25, 2018, 5:12:36 PM9/25/18
to redi...@googlegroups.com
Thanks Itamar but I'm still getting confused with the language. 

If a key has a TTL set, then it CAN be evicted anytime with this policy, even if the TTL is non-zero.

Assuming all expired keys are already evicted, then it is possible that soon to be expired keys (which are still alive) can still be evicted.

Wondering if there is a policy that can decide not to evict keys which still have a positive TTL?

-- 
Aditya Sanghi
Co-Founder & CTO


 

Itamar Haber

unread,
Sep 25, 2018, 5:45:09 PM9/25/18
to Redis DB
Sure - I'll try to explain better :)

> If a key has a TTL set, then it CAN be evicted anytime with this policy, even if the TTL is non-zero.

Yes. A non-zero TTL means that the key 1) exists (i.e. yet to expire) and 2) it is marked as volatile.

All eviction policies are triggered by memory pressure and operate only on existing keys. The `volatile-*` subgroup of eviction policies operate solely on volatile existing keys.

`volatile-ttl` picks the shortest-to-live keys from the candidates it samples (sample size is configurable), but small samples (default is 5 iirc) and significant percentages of long-lived keys in the keyspace increase the probability of these being evicted (instead of shorter-lived ones).

> Assuming all expired keys are already evicted, then it is possible that soon to be expired keys (which are still alive) can still be evicted.

Exactly! Expired keys are "evicted" first, but that's not really eviction because they don't (logically) exist anymore. If all memory was reclaimed and reallocated to existing keys, that's when the `maxmemory-policy` that is used kicks into action.

> Wondering if there is a policy that can decide not to evict keys which still have a positive TTL?

Actually, there is - it is called `noeviction` and it is the default. I hope this makes sense.

Aditya Sanghi

unread,
Sep 25, 2018, 5:50:48 PM9/25/18
to redi...@googlegroups.com
Perfectly clear now. Thanks Itamar!

-- 
Aditya Sanghi
Co-Founder & CTO


 

Peter

unread,
Aug 9, 2021, 5:08:49 PM8/9/21
to Redis DB
Hi, 

Are there other data store systems use sampling to pick up keys for eviction? 

Thanks

Reply all
Reply to author
Forward
0 new messages