# LATENCY DOCTOR

> Get a plain-English report on recorded latency spikes, with likely causes.

URL: https://docs.hotkv.com/commands/latency-doctor/

```
LATENCY DOCTOR
```

- Group: Server
- Complexity: O(N) where N is the number of spikes recorded
- HotKV Cloud: all plans
- On-Premise: no license needed

`LATENCY DOCTOR` summarises the latency monitor's data for people. For each
event with spikes it reports how many there were, over what period, how
recent the latest is, and the average and worst duration, followed by
advice for that kind of event (for example, which commands to look for in
[SLOWLOG GET](https://docs.hotkv.com/commands/slowlog-get/index.md) for `command` spikes, or adding jitter to
TTLs for `expire-cycle` spikes).

If nothing has been recorded, it tells you whether the monitor is off
(`latency-monitor-threshold` is `0`) and how to turn it on, or that no spike
reached the threshold.

## Return value

The report as text: a bulk string in RESP2, a verbatim string (`txt`) in
RESP3.

## Examples

```
127.0.0.1:6379> LATENCY DOCTOR
Latency monitoring is off: latency-monitor-threshold is 0. Set it to a number of milliseconds (CONFIG SET latency-monitor-threshold 100) to record what takes at least that long.
127.0.0.1:6379> CONFIG SET latency-monitor-threshold 50
OK
127.0.0.1:6379> LATENCY DOCTOR
Latency spikes of 50 ms or more (latency-monitor-threshold), by event:

1. command: 3 spikes in the last 310 s, the latest 5 s ago; 85 ms on average, 120 ms at worst.
   SLOWLOG GET shows the commands. Commands that walk large keys or the whole keyspace (KEYS, SMEMBERS, HGETALL, LRANGE 0 -1, SORT, scripts) are the usual cause: read large values in parts (SCAN, HSCAN, LRANGE with limits).
```

## Compatibility

Redis 7 and Valkey 8 have the same command. The report's wording and advice
are HotKV's own, so don't parse the text.

## See also

[LATENCY LATEST](https://docs.hotkv.com/commands/latency-latest/index.md), [SLOWLOG GET](https://docs.hotkv.com/commands/slowlog-get/index.md),
[MEMORY DOCTOR](https://docs.hotkv.com/commands/memory-doctor/index.md)