diff options
author | antirez <antirez@gmail.com> | 2014-03-20 11:47:12 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-03-20 11:47:12 +0100 |
commit | ad6b0f70b27712879c6435cb58edc5bff259f7a8 (patch) | |
tree | 38b4089bc0bbd487f0f790f6e68064112ddaf6cb /src/redis.c | |
parent | 1faf82663ff44d309a7a28989c1d99c8addf971c (diff) | |
download | redis-ad6b0f70b27712879c6435cb58edc5bff259f7a8.tar.gz |
Obtain LRU clock in a resolution dependent way.
For testing purposes it is handy to have a very high resolution of the
LRU clock, so that it is possible to experiment with scripts running in
just a few seconds how the eviction algorithms works.
This commit allows Redis to use the cached LRU clock, or a value
computed on demand, depending on the resolution. So normally we have the
good performance of a precomputed value, and a clock that wraps in many
days using the normal resolution, but if needed, changing a define will
switch behavior to an high resolution LRU clock.
Diffstat (limited to 'src/redis.c')
-rw-r--r-- | src/redis.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/redis.c b/src/redis.c index b8ed87325..7719745c8 100644 --- a/src/redis.c +++ b/src/redis.c @@ -843,9 +843,8 @@ void activeExpireCycle(int type) { } } -void updateLRUClock(void) { - server.lruclock = (mstime()/REDIS_LRU_CLOCK_RESOLUTION) & - REDIS_LRU_CLOCK_MAX; +unsigned int getLRUClock(void) { + return (mstime()/REDIS_LRU_CLOCK_RESOLUTION) & REDIS_LRU_CLOCK_MAX; } /* Add a sample to the operations per second array of samples. */ @@ -1044,19 +1043,18 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { run_with_period(100) trackOperationsPerSecond(); - /* We have just 22 bits per object for LRU information. - * So we use an (eventually wrapping) LRU clock with 10 seconds resolution. - * 2^22 bits with 10 seconds resolution is more or less 1.5 years. + /* We have just REDIS_LRU_BITS bits per object for LRU information. + * So we use an (eventually wrapping) LRU clock. * - * Note that even if this will wrap after 1.5 years it's not a problem, - * everything will still work but just some object will appear younger - * to Redis. But for this to happen a given object should never be touched - * for 1.5 years. + * Note that even if the counter wraps it's not a big problem, + * everything will still work but some object will appear younger + * to Redis. However for this to happen a given object should never be + * touched for all the time needed to the counter to wrap, which is + * not likely. * * Note that you can change the resolution altering the - * REDIS_LRU_CLOCK_RESOLUTION define. - */ - updateLRUClock(); + * REDIS_LRU_CLOCK_RESOLUTION define. */ + server.lruclock = getLRUClock(); /* Record the max memory used since the server was started. */ if (zmalloc_used_memory() > server.stat_peak_memory) @@ -1421,7 +1419,7 @@ void initServerConfig() { server.migrate_cached_sockets = dictCreate(&migrateCacheDictType,NULL); server.loading_process_events_interval_bytes = (1024*1024*2); - updateLRUClock(); + server.lruclock = getLRUClock(); resetServerSaveParams(); appendServerSaveParams(60*60,1); /* save after 1 hour and 1 change */ |