Per Reclaim expired keys memory faster,

You can follow one of these three steps to reclaim the memory:

  • Restart your redis-server
  • Increase memorysamples in redis conf. (default is 5, max is 10) so that expired keys are reclaimed faster.
  • You can set up a cron job that runs the scan command after an interval which helps in reclaiming the memory of the expired keys.
  • Alternatively, Increasing the expiry of keys also helps.

As we know, Redis uses a randomized algorithm to find out keys that should be expired, so the second method would increase the probability of expired keys being reclaimed.

The third method the scan method could force a passive removal across all the keyspace

I am confused why the fourth method Increasing the expiry of keys could reclaim expired keys faster? Could someone give me more details?

Comment From: sundb

I also can't understand the meaning of Increasing the expiry of keys, looks like it should be wrong. ping @itamarhaber

Comment From: itamarhaber

Aye, needs to be corrected - @richzw could I bother you moving this issue here: https://github.com/RedisLabs/redislabs-docs/edit/master/content/ri/memory-optimizations.md

Comment From: richzw

Reclaim expired keys memory faster,

Done. I just remove the fourth method of Reclaim expired keys memory faster, and pull request had done. Please correct me if something is wrong or if anything am I missing.

@itamarhaber

Comment From: enjoy-binbin

for the record, i was tracked in https://github.com/RedisLabs/redislabs-docs/pull/1931

Comment From: judeng

@sundb @richzw @itamarhaber I think the fourth item may be meaningful. I reread the activeExpireCycle function, when a large number of keys expire at one time, the memory reclamation may be slow, so the real meaning of Increasing the expiry of keys may be to say not to set the same expiration time. In any case, it does need to modify the description.

void activeExpireCycle(int type) {
...
            /* We can't block forever here even if there are many keys to
             * expire. So after a given amount of milliseconds return to the
             * caller waiting for the other active expire cycle. */
            if ((iteration & 0xf) == 0) { /* check once every 16 iterations. */
                elapsed = ustime()-start;
                if (elapsed > timelimit) {
                    timelimit_exit = 1;
                    server.stat_expired_time_cap_reached_count++;
                    break;
                }
            }
...
}

Comment From: sundb

@judeng Yeah, I also thought that this phrase was meant to spread out the expiration time.

Comment From: richzw

@sundb @richzw @itamarhaber I think the fourth item may be meaningful. I reread the activeExpireCycle function, when a large number of keys expire at one time, the memory reclamation may be slow, so the real meaning of Increasing the expiry of keys may be to say not to set the same expiration time. In any case, it does need to modify the description.

c void activeExpireCycle(int type) { ... /* We can't block forever here even if there are many keys to * expire. So after a given amount of milliseconds return to the * caller waiting for the other active expire cycle. */ if ((iteration & 0xf) == 0) { /* check once every 16 iterations. */ elapsed = ustime()-start; if (elapsed > timelimit) { timelimit_exit = 1; server.stat_expired_time_cap_reached_count++; break; } } ... }

Maybe we could make the sentence Increasing the expiry of keys also helps. more clear.