>_ IzzyLab

Hands-on task

This task is step 6 of the course “Redis in production”

The slowest command in SLOWLOG

medium~7 min

Users complain that Redis "freezes" for hundreds of milliseconds from time to time. Redis is single-threaded: while one heavy command runs, all other clients wait.

The slow command log is already enabled and has collected some entries. Find the slowest command in it (the one with the longest execution time) and write only its name to /root/slow.txt — a single word, for example KEYS.

Don't clear the log and don't change the settings.

What you'll practise:
  • redis
  • SLOWLOG
  • slowlog-log-slower-than
  • performance

Topic breakdown

Redis executes commands in a single thread, so one O(N) command on a large key — KEYS, SORT, LRANGE over a whole list, HGETALL/SMEMBERS on huge collections — blocks all other clients for as long as it runs. SLOWLOG records commands whose execution (excluding network latency and queueing) took longer than slowlog-log-slower-than microseconds; the log keeps the last slowlog-max-len entries in memory. It is the first tool to reach for when people complain about "freezes": find which command on which key eats the time, then rewrite it (SCAN instead of KEYS, LRANGE in chunks, sorting in the application or via a sorted set) or split the big key.

What's checked

  1. /root/slow.txt created
  2. the slowest command found

What it looks like