Slow commands on big keys are the usual cause. Redis runs commands one at a time, so one slow command makes every other client wait.
Common causes are O(N) commands on big collections:
KEYS.SMEMBERSon a huge set, orHGETALLon a hash with millions of fields.LRANGE 0 -1on a huge list.SORT.DELon a very large key.DELfrees the memory synchronously, so the thread waits until it is done.
How to find them:
SLOWLOG GETlists commands that took longer than the threshold.LATENCY DOCTORreports latency events.redis-cli --bigkeysor--memkeysfinds keys that are too big.- Long-running Lua scripts also show up in these tools.
Fixes:
- Replace
KEYSwithSCAN. - Replace full reads with
HSCANorSSCAN, or read a range at a time. - Split big keys into smaller ones.
- Delete large keys with
UNLINK. It removes the key at once and frees the memory in a background thread.
- Commands run on a single thread, so one slow command delays everyone.
- Big keys and O(N) commands are the usual cause.
- Find them with
SLOWLOG,LATENCY DOCTORand--bigkeysor--memkeys. - Use the
SCANfamily of commands and split big keys. UNLINKfrees memory in the background, whileDELblocks the thread.
Read more