> ## Documentation Index
> Fetch the complete documentation index at: https://docs.shiftlabs.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Slow Log

> Monitor and analyze slow Redis commands for performance optimization

The Redis Slow Log captures commands that exceed a configured execution time threshold. Use it to identify performance bottlenecks, optimize queries, and monitor command patterns that impact your application.

## Key Concepts

<CardGroup cols={2}>
  <Card title="Slow Log" icon="clock">
    An in-memory log of commands that exceeded the configured duration threshold.
  </Card>

  <Card title="Threshold" icon="gauge">
    Commands slower than `slowlog-log-slower-than` microseconds are logged.
  </Card>

  <Card title="Execution Time" icon="timer">
    Time spent executing the command, not including network latency or queue time.
  </Card>

  <Card title="Log Size" icon="list">
    Maximum entries stored is controlled by `slowlog-max-len` configuration.
  </Card>
</CardGroup>

## Required Permissions

| Action        | Permission                              |
| ------------- | --------------------------------------- |
| View slow log | `iam:project:infrastructure:redis:read` |

## Duration Severity Levels

| Level        | Duration    | Meaning                                 |
| ------------ | ----------- | --------------------------------------- |
| **Normal**   | \< 10ms     | Typical command execution               |
| **Warning**  | 10ms - 99ms | Potentially slow, worth investigating   |
| **Critical** | >= 100ms    | Very slow, likely impacting performance |

## How to View Slow Log

<Steps>
  <Step title="Select Connection">
    Choose a Redis connection from the dropdown.
  </Step>

  <Step title="Browse Entries">
    Slow log entries are displayed with ID, timestamp, command, client, and duration.
  </Step>

  <Step title="Filter Results">
    Use search, client filter, or duration filter to find specific entries.
  </Step>
</Steps>

## How to Search Commands

<Steps>
  <Step title="Enter Search Term">
    Type a command or keyword in the search box.
  </Step>

  <Step title="View Matches">
    Results filter to show only entries containing the search term.
  </Step>
</Steps>

<Tip>
  Search for specific commands like `KEYS`, `SCAN`, or `SORT` to find common performance issues.
</Tip>

## How to Filter by Client

<Steps>
  <Step title="Enter Client Address">
    Type an IP address or client name in the client filter.
  </Step>

  <Step title="View Client Commands">
    Results show only slow commands from matching clients.
  </Step>
</Steps>

## How to Filter by Duration

<Steps>
  <Step title="Select Duration Threshold">
    Choose from preset duration filters:

    * **All**: Show all slow log entries
    * **> 1ms**: Commands slower than 1 millisecond
    * **> 5ms**: Commands slower than 5 milliseconds
    * **> 10ms**: Commands slower than 10 milliseconds
    * **> 50ms**: Commands slower than 50 milliseconds
    * **> 100ms**: Commands slower than 100 milliseconds
  </Step>

  <Step title="Review Filtered Results">
    Only entries exceeding the selected duration are displayed.
  </Step>
</Steps>

## Understanding Slow Log Entries

Each entry contains:

| Field           | Description                                            |
| --------------- | ------------------------------------------------------ |
| **ID**          | Sequential entry number (decrements for older entries) |
| **Timestamp**   | When the command was executed                          |
| **Command**     | The full command with arguments                        |
| **Client**      | IP address and port of the client                      |
| **Client Name** | Optional name set by CLIENT SETNAME                    |
| **Duration**    | Execution time in microseconds/milliseconds            |

## Common Slow Commands

| Command                | Why It's Slow           | Alternative                      |
| ---------------------- | ----------------------- | -------------------------------- |
| `KEYS *`               | Scans entire keyspace   | Use `SCAN` with patterns         |
| `SMEMBERS` (large set) | Returns all members     | Use `SSCAN` for pagination       |
| `HGETALL` (large hash) | Returns all fields      | Use `HSCAN` or specific `HGET`   |
| `SORT`                 | CPU-intensive operation | Pre-sort data or use sorted sets |
| `LRANGE 0 -1`          | Returns entire list     | Paginate with offset/count       |
| `DEBUG SLEEP`          | Intentional delay       | Remove from production           |

## How to Configure Slow Log

The slow log is configured through Redis configuration parameters.

### Threshold Setting

```
slowlog-log-slower-than <microseconds>
```

| Value   | Meaning                                 |
| ------- | --------------------------------------- |
| `10000` | Log commands slower than 10ms (default) |
| `1000`  | Log commands slower than 1ms            |
| `0`     | Log all commands (debugging only)       |
| `-1`    | Disable slow log                        |

### Maximum Entries

```
slowlog-max-len <count>
```

| Value  | Meaning                         |
| ------ | ------------------------------- |
| `128`  | Keep last 128 entries (default) |
| `1000` | Keep more history for analysis  |
| `0`    | Unlimited (uses memory)         |

<Info>
  Configure these settings in the Redis Configuration page. Changes take effect immediately.
</Info>

## How to Clear Slow Log

The slow log can be cleared using Redis CLI:

```bash theme={null}
SLOWLOG RESET
```

<Warning>
  Clearing the slow log removes all entries permanently. Export or document important findings before clearing.
</Warning>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Slow log is empty" icon="circle-question">
    * The threshold may be set too high (lower `slowlog-log-slower-than`)
    * Slow log may have been recently reset
    * Commands may genuinely be fast
    * Check if slow log is disabled (`slowlog-log-slower-than -1`)
  </Accordion>

  <Accordion title="Too many entries" icon="circle-question">
    * Increase threshold to capture only slower commands
    * Use duration filter to focus on critical entries
    * Check for problematic command patterns
    * Consider application optimization
  </Accordion>

  <Accordion title="Same command appearing repeatedly" icon="circle-question">
    * Identify the calling application
    * Check for inefficient loops or queries
    * Consider caching results
    * Optimize the command or data structure
  </Accordion>

  <Accordion title="KEYS command in slow log" icon="circle-question">
    * Replace with SCAN command
    * KEYS blocks the server during execution
    * Never use KEYS in production code
    * Consider using key naming conventions for SCAN patterns
  </Accordion>

  <Accordion title="Large collection commands slow" icon="circle-question">
    * Use SCAN variants (SSCAN, HSCAN, ZSCAN)
    * Paginate with LIMIT when possible
    * Consider breaking large collections into smaller ones
    * Check if all data is actually needed
  </Accordion>

  <Accordion title="Write commands appearing slow" icon="circle-question">
    * Check persistence settings (AOF fsync)
    * Monitor disk I/O
    * Large values take longer to write
    * Check replication lag if using replicas
  </Accordion>
</AccordionGroup>

## FAQ

<AccordionGroup>
  <Accordion title="What counts as execution time?">
    Execution time measures only the time Redis spends processing the command. It does not include network latency, client queue time, or time waiting for slow log recording.
  </Accordion>

  <Accordion title="Does the slow log impact performance?">
    Minimal impact. The slow log is stored in memory with a fixed size limit. Recording entries is fast. Very high-traffic systems with `slowlog-log-slower-than 0` may see slight overhead.
  </Accordion>

  <Accordion title="How long are entries retained?">
    Entries are kept until the log reaches `slowlog-max-len` entries. Oldest entries are removed when new ones are added. The log is also cleared on server restart.
  </Accordion>

  <Accordion title="Why is my fast command in the slow log?">
    The default threshold is 10ms. Commands just over this appear in the log. During high load, normally fast commands may slow down due to queueing or CPU contention.
  </Accordion>

  <Accordion title="Can I export slow log data?">
    Use `SLOWLOG GET <count>` in Redis CLI to retrieve entries. The UI displays entries for analysis; use CLI for programmatic export.
  </Accordion>

  <Accordion title="What's a good threshold for production?">
    Start with the default 10ms. Adjust based on your latency requirements. For real-time applications, consider 1-5ms. For batch processing, 50-100ms may be acceptable.
  </Accordion>

  <Accordion title="Why is SCAN not a complete solution for KEYS?">
    SCAN is non-blocking and cursor-based, so it doesn't freeze Redis. However, scanning millions of keys still takes time. Use specific patterns and limit result sets.
  </Accordion>

  <Accordion title="How do I identify which application is causing slow commands?">
    Use CLIENT SETNAME in your applications to set descriptive client names. The slow log will show these names, making it easy to trace commands to specific services.
  </Accordion>
</AccordionGroup>

## Best Practices

### Monitoring

* Review slow log regularly, not just during incidents
* Set up alerts for unusual slow log growth
* Track common slow commands over time
* Compare slow log patterns after deployments

### Threshold Tuning

* Start with defaults, adjust based on requirements
* Lower threshold during optimization efforts
* Raise threshold if log fills too quickly
* Consider different thresholds for different environments

### Command Optimization

* Replace KEYS with SCAN patterns
* Use pipeline for multiple commands
* Paginate large collection reads
* Consider data structure changes for frequent slow operations

### Application Design

* Set CLIENT SETNAME for each service
* Cache frequently accessed data
* Batch operations when possible
* Monitor client-side latency alongside slow log
