The Redis Latency Monitor for Systematic Performance Diagnosis
AI generated
SET
TTL
Redis / Security & Operations
The Latency Monitor for Systematic Performance Diagnosis
How LATENCY HISTORY and LATENCY DOCTOR classify latency spikes and uncover causes together with the slowlog

Sporadic latency spikes are among the most unpleasant performance problems in a Redis instance, because they can neither be reproduced with a single command nor explained by a simple load measurement. The built-in latency monitor was designed exactly for this case: it internally logs several event classes, from slow commands through fork operations to the expiry cycle of expired keys, and exposes them through the LATENCY HISTORY, LATENCY LATEST, and LATENCY DOCTOR commands. This article covers how these event classes work in detail, how the latency monitor combines usefully with the classic slowlog, and what a systematic diagnostic workflow looks like when latency problems occur only occasionally and seemingly at random.

10 min read Latency Monitor Diagnostic Workflow

1. When the slowlog is not enough for diagnosis

The classic slowlog logs only individual commands whose execution time exceeds a configured threshold, making it ideal for identifying specific slow commands. Many latency problems in Redis, however, do not arise within command execution itself at all, but through internal operations such as a fork process for an RDB snapshot, deleting a large temporary file, or an expensive expiry cycle for keys with a TTL set, none of which show up in the slowlog at all.

The latency monitor closes exactly this gap by logging not only commands but various internal event classes along with their respective duration. That way, a latency spike that leaves no trace in the slowlog, because no single command took an unusually long time, can still be traced back to a concrete internal cause, which makes the decisive difference especially for sporadic, hard-to-reproduce problems.

2. Activation via latency-monitor-threshold

The latency monitor is activated through the latency-monitor-threshold configuration directive, which specifies in milliseconds the duration above which an event is recorded at all. A value of zero disables recording entirely, while a low value like one hundred milliseconds already captures moderate outliers without burdening the instance with an excessive number of logged events.

Unlike some other diagnostic tools, enabling the latency monitor itself carries negligible performance overhead, since it merely compares already measured internal timestamps against the threshold. For production environments, it is therefore recommended to keep the monitor permanently active rather than switching it on only for an acute problem, since sporadic events would otherwise go uncaptured exactly when they actually occur.


# Permanently enable the latency monitor with a 100ms threshold
redis-cli CONFIG SET latency-monitor-threshold 100
redis-cli CONFIG REWRITE

3. LATENCY HISTORY and the most important event classes

The LATENCY HISTORY command followed by an event name returns a list of past incidents of that class, each with its timestamp and measured duration. The most important event classes include command for commands that may sit below the slowlog threshold but are still relevant, fork for the duration of a fork operation during RDB or AOF persistence, expire-cycle for the periodic background process that removes expired keys, and rdb-unlink-temp-file for deleting a temporary snapshot file.

This breakdown by event class allows for a targeted investigation: frequent, growing fork events point to a dataset that has become too large for the configured persistence strategy, while recurring expire-cycle outliers rather point to a very large number of keys expiring simultaneously, a pattern that arises, for example, when many cache entries with an identical TTL were created at exactly the same time.


# Inspect the recent history of fork events
redis-cli LATENCY HISTORY fork
redis-cli LATENCY HISTORY expire-cycle

4. LATENCY LATEST for a quick overall overview

While LATENCY HISTORY focuses on a single event class, LATENCY LATEST returns a compact overview of every event class that has had at least one incident since the last reset, each with the time of the latest incident, its duration, and the maximum duration measured so far for that class.

This command is an excellent starting point for an acute latency investigation, since it shows in a single query which event classes are relevant at all before digging deeper into a specific class with LATENCY HISTORY. An empty result from LATENCY LATEST while application-side latency problems are simultaneously being observed is itself important diagnostic information, since it suggests the cause lies outside Redis, for example in the network or the application itself.

5. LATENCY DOCTOR as an automated analysis

LATENCY DOCTOR summarizes the recorded events in human-readable text and automatically maps noticeable patterns to known causes, such as a dataset that has grown too large for fork-based persistence or an unusually high number of keys expiring simultaneously. The output includes not just the raw observation but also concrete recommendations, phrased in plain language instead of a bare column of numbers.

It is important to treat LATENCY DOCTOR as a starting point rather than a final answer: the automated analysis reliably recognizes known, common patterns, but cannot always correctly separate unusual or overlapping causes. For more complex cases, manually inspecting LATENCY HISTORY for individual event classes remains indispensable to actually confirm the explanation LATENCY DOCTOR suggests.


redis-cli LATENCY DOCTOR

6. How it interacts with the slowlog

The latency monitor and the slowlog complement each other, since they represent different slices of the same reality: the slowlog answers the question of which specific command took an unusually long time, while the latency monitor answers the broader question of when and through what the instance overall was noticeably delayed, regardless of whether a single command or an internal background process was responsible.

In practice, a combined view pays off: if LATENCY LATEST shows a cluster of command events at a particular point in time, a subsequent look at SLOWLOG GET for the same period reveals the specific commands responsible, including their full arguments. Without this combined view, it would remain unclear either which command was at fault, or whether a command was even the cause at all rather than an internal process.


redis-cli LATENCY LATEST
redis-cli SLOWLOG GET 20

7. A practical diagnostic workflow for sporadic latency spikes

A proven workflow starts by making sure latency-monitor-threshold is permanently active, so events are actually captured as soon as they occur, instead of having to be laboriously reproduced only after the application side complains. Once a sporadic problem is reported, LATENCY LATEST provides a quick overview as the first step of which event classes are affected at all.

In the second step, LATENCY HISTORY for the most noticeable class delivers the time distribution of incidents, which can be cross-checked against external events such as deployment times, cron jobs, or backup windows. Only in the third step does LATENCY DOCTOR come in as a summarizing interpretation, followed by a comparison with the slowlog for the same period to determine whether specific application commands or internal Redis processes were the actual cause.

8. Typical causes behind common event classes

Frequent fork events with growing duration usually correlate directly with dataset size, since the fork operation has to copy more page table entries with larger data volumes, which can be narrowed down further with DEBUG OBJECT or MEMORY USAGE for individual suspiciously large keys. Frequent expire-cycle events, on the other hand, usually point to an unfortunate distribution of TTL values, where a very large number of keys expire simultaneously instead of being spread evenly over time.

Command events without a recognizable pattern in the slowlog that still show up in the latency monitor often point to operating-system-level causes, such as swapping due to insufficient memory or CPU throttling in a container environment with overly tight resource limits, causes that neither the slowlog nor the latency monitor names directly, but which are suggested by the sudden, seemingly unmotivated occurrence.

9. LATENCY RESET and integration into monitoring

The LATENCY RESET command clears the internally stored history of one or all event classes and is especially useful after a targeted optimization measure, such as adjusting TTL distributions or changing the persistence strategy, to measure again from a clean baseline whether the measure actually worked.

For lasting historization beyond a plain snapshot command, a regular, for example minutely, cron job that queries LATENCY LATEST and forwards the results into an external monitoring system like Prometheus is worthwhile, instead of relying exclusively on Redis's own limited, internally stored event count, which automatically discards the oldest entries once there are very many incidents.


# Reset the history of a specific event class
redis-cli LATENCY RESET fork
redis-cli LATENCY RESET
Latency Event Typical Cause Diagnostic Tool Countermeasure
command a single slow command in application code LATENCY HISTORY plus SLOWLOG GET optimize the command or replace it with a non-blocking variant
fork large dataset during RDB or AOF persistence LATENCY HISTORY fork, MEMORY USAGE adjust the persistence strategy or reduce dataset size
expire-cycle very many keys with an identical TTL expiring at once LATENCY HISTORY expire-cycle add jitter to TTL values to spread out expiry times
rdb-unlink-temp-file deleting a large temporary snapshot file LATENCY HISTORY rdb-unlink-temp-file check for faster storage media or smaller snapshot intervals
aof-write slow write speed of the underlying storage LATENCY HISTORY aof-write adjust the AOF fsync policy or use faster storage

Mironsoft

Cache layer setup and Magento Redis integration

Magento cache that isn't quite working or is misconfigured?

We set up Redis as a cache and session backend for Magento cleanly, tune memory usage and eviction strategies, and make sure full page cache and session storage work together reliably.

Redis Setup

Configure the cache, session, and FPC backend production-ready for Magento.

Memory Tuning

Match memory usage and eviction policies to the shop's actual load.

High Availability Setup

Set up Redis Sentinel or Cluster for resilient Magento environments.

10. Summary

Latency Monitor in Redis: Key Takeaways

Complements the slowlog specifically

The latency monitor captures internal operations like fork and expiry cycles that are not visible in the slowlog.

Event classes as a diagnostic axis

command, fork, expire-cycle, and other classes systematically narrow down the cause of a latency spike.

LATENCY DOCTOR as a starting point

The automated analysis recognizes known patterns but does not replace manually inspecting the details.

Combining it with the slowlog is decisive

Only looking at both tools together clarifies whether a command or an internal process was the cause.

11. FAQ: Latency Monitor in Redis: Key Takeaways

1What fundamentally distinguishes the latency monitor from the slowlog?
The slowlog logs only individual slow commands, while the latency monitor additionally captures internal operations like fork processes and expiry cycles that never show up in the slowlog at all.
2How is the latency monitor activated?
Through the latency-monitor-threshold configuration directive in milliseconds, where a value of zero disables recording and a low value like 100 already captures moderate outliers.
3Does an activated latency monitor cause noticeable performance overhead?
No, the overhead is negligible, since it merely compares already measured internal timestamps against the configured threshold, which is why permanent activation is recommended.
4What does the LATENCY LATEST command specifically show?
A compact overview of every event class with at least one incident since the last reset, each with the time, duration, and maximum duration measured so far.
5What is LATENCY DOCTOR good for and where are its limits?
LATENCY DOCTOR summarizes events in readable form and automatically maps known patterns to causes, but cannot always correctly separate unusual or overlapping causes.
6Why do many fork events usually point to a dataset that has grown too large?
Because the fork operation has to copy more page table entries with larger data volumes, so its duration correlates directly with dataset size.
7What is a typical cause of frequent expire-cycle events?
An unfortunate distribution of TTL values, where a very large number of keys expire at exactly the same time instead of being spread evenly over time.
8How can the latency monitor be usefully combined with the slowlog?
If LATENCY LATEST shows a cluster of command events at a particular time, SLOWLOG GET for the same period reveals the specific commands responsible for it.
9When should LATENCY RESET be used?
Mainly after a targeted optimization measure, to measure again from a clean baseline whether the measure actually worked.
10How can the limited, internally stored event history be worked around?
Through a regular cron job that queries LATENCY LATEST and forwards the results permanently into an external monitoring system like Prometheus.