3. In computing, a cache is a hardware or software component that
stores data so that future requests for that data can be served
faster
The Architecture of Computer Hardware and Systems Software,
An Information Technology Approach
~ Irv Englander
4. A cache hit occurs when the requested data can be found in a
cache, while a cache miss occurs when it cannot.
The more requests that can be served from the cache,
the faster the system performs.
13. 13
LRU = Least Recently Used
•If you’ve used an item from your cache recently - you’re more
likely to use it again.
•The longer you haven’t used an item, the smaller the chance
you’ll need it again
14. 14
Since LRU is itself an approximation
of what we want to achieve, how about
approximating LRU itself?
Salvatore Sanfilipo, Blog post
16. 16
Sample X random keys and evict the
one with the highest idle time
maxmemory-samples
17. Commit: 165346ca29972817b1245e689315edeba1fe369b [165346ca]
Author: antirez <antirez@gmail.com>
Date: October 14, 2010 at 20:22:21 GMT+1
# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached? You can select among five behaviors:
#
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys->random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
#
# maxmemory-policy volatile-lru
20. 20
2009 2018
March 29th
First commit
May 2009
maxmemory
implemented
October 2010
LRU implemented
November 2010
noeviction
policy added
v 2.2
alpha 3
v 2.2
alpha 5
21. ...if you look at this algorithm *across* its executions,
you can see how we are trashing
a lot of interesting data
Salvatore Sanfilipo, Blog post
22. First rule of Fight Club is:
observe your algorithms with naked eyes
Salvatore Sanfilipo, Blog post
23.
24. 24
LRU v2
• Use a pool of best candidates for eviction (maxmemory-samples)
• All sampled keys are compared against the keys in the pool and if they're
more adapt to eviction compared to a key in the pool - they switch places
•After all N keys have benn compared, the best candidate is evicted from
the pool
26. 26
2009 2018
March 29th
First commit
May 2009
maxmemory
implemented
October 2010
LRU implemented
November 2010
noeviction
policy added
v 2.2
alpha 3
v 2.2
alpha 5
March 2014
- LRU eviction pool
- maxmemory-samples = 5
- LRU field changed to 24 bits
(v 2.8.8)
v 3.0
Default policy
noeviction
v 2.8.8
27.
28. 28
2009 2018
March 29th
First commit
May 2009
maxmemory
implemented
October 2010
LRU implemented
November 2010
noeviction
policy added
July 2016
Cross-database
eviction
March 2014
- LRU eviction pool
- maxmemory-samples = 5
- LRU field changed to 24 bits
(v 2.8.8)
v 3.0
Default policy
noeviction
v 2.8.8
v 2.2
alpha 3
v 2.2
alpha 5
29. r this subsystem of Redis was stimulated again at that point. I wan
Salvatore Sanfilipo, Blog post
30. probability of being accessed in the future, that are the keys *mos
Salvatore Sanfilipo, Blog post
35. 35
24 bits
reduced-precision unix time
less significant bits of the UNIX time converted
to minutes
Todo: show the "math"
16 bits
Last decrease
time
8 bits
LOG C
37. 37
2009 2018
March 29th
First commit
May 2009
maxmemory
implemented
October 2010
LRU implemented
November 2010
noeviction
policy added
July 2016
Cross-database
eviction
March 2014
- LRU eviction pool
- maxmemory-samples = 5
- LRU field changed to 24 bits
(v 2.8.8)
v 3.0
Default policy
noeviction
v 2.8.8
July 2014
- LFU Implementation
- Volatile-ttl uses the pool
v 4.0
v 2.2
alpha 3
v 2.2
alpha 5