Analizzare lo slow log
Usi lo slow log di Redis per trovare i comandi che bloccano il server, interpretare le voci e regolare le soglie che ne determinano la registrazione.
Analizzare lo slow log è una lezione Redis Caching & Messaging (Pub/Sub, Streams) gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Redis Caching & Messaging (Pub/Sub, Streams), e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Redis Caching & Messaging (Pub/Sub, Streams) include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
Redis Is Single-Threaded
Command execution in Redis is effectively single-threaded. One slow command blocks every other client. The slow log records commands whose execution time exceeds a threshold, so you can hunt down these blockers.
What It Measures
The slow log times only command execution, not network or I/O wait. So a logged entry means Redis itself spent that long, usually on an expensive operation over many elements.
Configuring the Threshold
slowlog-log-slower-than sets the threshold in microseconds. A value of 10000 logs commands slower than 10ms. Set it to 0 to log everything (for debugging) or -1 to disable.
CONFIG SET slowlog-log-slower-than 10000Limiting Log Size
slowlog-max-len caps how many entries are retained; older ones are evicted. This keeps memory bounded.
CONFIG SET slowlog-max-len 128Reading the Log
SLOWLOG GET returns recent entries; pass a count to limit them. Each entry has an ID, timestamp, microsecond duration, the command and arguments, and the client address.
SLOWLOG GET 10Interpreting an Entry
Look at the command and its duration. A KEYS * or a large SMEMBERS over a million-element set will show big durations, pinpointing the culprit and the calling client.
# 1) id 14
# 2) timestamp 1716900000
# 3) microseconds 23000
# 4) ["KEYS", "*"]Length and Reset
SLOWLOG LEN gives the current entry count, and SLOWLOG RESET clears the log, handy before reproducing an issue.
SLOWLOG LEN
SLOWLOG RESETCommon Offenders
Frequent slow-log culprits:
KEYSon large keyspaces (useSCAN)- Big
SMEMBERS/HGETALL/LRANGE 0 -1 - Unbounded
SORT - Large
DEL(useUNLINK)
SCAN 0 MATCH user:* COUNT 100
UNLINK biglistFrom Detection to Fix
Once the slow log names a command, fix it: paginate with cursors, model data to avoid huge single keys, or move heavy work off the hot path. Re-check the log to confirm the durations drop.
Continuous Monitoring
Sample the slow log periodically from a monitoring job and alert when slow commands appear, so you catch regressions before users feel them.
redis-cli SLOWLOG GET 5Threshold Tuning
Start with a moderate threshold (e.g. 10ms) in production. Lower it temporarily when investigating, then restore it, because logging everything adds a tiny per-command cost.
Quick Check
Test your understanding of the slow log.
Recap
You learned to use the slow log: configure slowlog-log-slower-than and slowlog-max-len, read entries with SLOWLOG GET, interpret durations, and fix common offenders like KEYS and huge single-key reads. Monitor it continuously to catch performance regressions early.
Impara Redis Caching & Messaging (Pub/Sub, Streams) con un tutor IA — gratis
Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.
- Corsi
- 12
- Lezioni
- 48
Domande Frequenti
La lezione «Analizzare lo slow log» è gratuita?
Sì — il testo completo di «Analizzare lo slow log» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Redis Caching & Messaging (Pub/Sub, Streams), passa a CoddyKit PRO. Il corso Redis Caching & Messaging (Pub/Sub, Streams) include 4 lezioni in totale.
Cosa imparerò in «Analizzare lo slow log»?
Usi lo slow log di Redis per trovare i comandi che bloccano il server, interpretare le voci e regolare le soglie che ne determinano la registrazione. Eserciti Redis Caching & Messaging (Pub/Sub, Streams) con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Redis Caching & Messaging (Pub/Sub, Streams)?
Non è richiesta alcuna esperienza precedente. Redis Caching & Messaging (Pub/Sub, Streams) su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Analizzare lo slow log»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Redis Caching & Messaging (Pub/Sub, Streams)?
Sì. Ogni lezione Redis Caching & Messaging (Pub/Sub, Streams) include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Strumenti di monitoraggio di Redis
- Diagnosticare i problemi di prestazioni
- Ottimizzazione e tuning delle prestazioni
- Analizzare lo slow log