adubkov / zbx_redis_template

Zabbix template for Redis
129 stars 102 forks source link

use SCAN instead of KEYS for llen #10

Closed i-trofimtschuk closed 9 years ago

i-trofimtschuk commented 9 years ago

using scan_iter from redis.py for not blocking the whole redis instance when you have many keys

i-trofimtschuk commented 9 years ago

for explanations see https://github.com/blacked/zbx_redis_template/commit/e96a0c275fa2503eba51ed281830d8e827e6e91b


the difference between SCAN and KEYS is that KEYS will retrieve all keys at once, which will block your whole redis together with all other redis-calls beeing made during that time as redis is single threaded.

if you have many keys, KEYS can easily take several seconds and as said above all other calls made during that time will wait for it to complete, meaning the simplest operations will queue up and wait, also taking several seconds to complete.

SCAN on the other hand will retrieve the KEYS in chunks and only take about the same time normal redis calls will which if far below a second.

using SCAN iterating over all keys and using TYPE on every one them will still induce some serious load on your redis instance but at least will not make other commands block and wait for the one KEYS call to complete