Hello all,
today I updated the latency documentation with a new latency source:
tons of keys expiring at the same moment.
Please see
http://redis.io/topics/latency section "Latency generated
by expires", where the issue is explained in details.
So the issue is, when this happens Redis currently will block
everything and expire keys in a busy loop til the number of already
expired keys (in the total of keys with an expire) became 25% or less.
25% is considered an acceptable memory waste to continue serving
queries again, expiring the remaining keys 100 per second,
incrementally.
The current behavior is:
1) Good because it reclaims memory ASAP.
2) Bad because it blocks the server.
However thee is a way to modify it. Given that the expire cycle is ran
every 100 milliseconds, we could say Redis, for instance, that even
when there is to expire more and more, it does not use more than,
let's say, 25 milliseconds of busy looping, and use the remaining 75
ms to serve clients. This way it will take 4 times the time needed
formerly in order to reclaim the memory, but in the meantime it will
be able to serve clients.
The current behavior is more simple and deterministic, but the
modified behavior may be preferible. I would like to start a
discussion about this with the interested parties in order to see what
we can do.
In the meantime, this is how to reproduce the problem in Redis >= 2.6-rc3
Start a spare Redis instance, then fill it with:
$ redis-benchmark -P 32 -q -r 1000000 -n 1000000 set k:rand:000000000000 value
set k:rand:000000000000 value: 275482.09 requests per second
$ redis-cli dbsize
(integer) 632486
Set an expire to all this keys, in the exact same moment:
$ tclsh
% expr [clock milliseconds]+60000
1336752485417
% exit
$ redis-benchmark -P 32 -q -r 1000000 -n 1000000 pexpireat
k:rand:000000000000 1336752485417
pexpireat k:rand:000000000000 1336752485417: 257997.94 requests per second
Now run redis-cli --latency and wait up to 60 seconds:
min: 0, max: 1964, avg: 0.50 (15850 samples)
The server blocked for almost 2 seconds.
Cheers,
Salvatore
--
Salvatore 'antirez' Sanfilippo
open source developer - VMware
http://invece.org
Beauty is more important in computing than anywhere else in technology
because software is so complicated. Beauty is the ultimate defence
against complexity.
— David Gelernter