Back to Redis

Redis Slow Log

content/operate/rs/7.8/clusters/logging/redis-slow-log.md

latest6.0 KB
Original Source

[Redis slow log]({{<relref "/commands/slowlog">}}) is one of the best tools for debugging and tracing your Redis database, especially if you experience high latency and high CPU usage with Redis operations. Because Redis is based on a single threaded architecture, Redis slow log can be much more useful than slow log mechanisms of multi-threaded database systems such as MySQL slow query log.

Unlike tools that introduce lock overhead, which complicates the debugging process, Redis slow log is highly effective at showing the actual processing time of each command.

Redis Software slow log enhancements

Redis Software includes enhancements to the standard Redis slow log capabilities that allow you to analyze the execution time complexity of each command. This enhancement can help you better analyze Redis operations, allowing you to compare the differences between execution times of the same command, observe spikes in CPU usage, and more.

This is especially useful with complex commands such as [ZUNIONSTORE]({{<relref "/commands/zunionstore">}}), [ZINTERSTORE]({{<relref "/commands/zinterstore">}}), and [ZRANGEBYSCORE]({{<relref "/commands/zrangebyscore">}}).

The enhanced Redis Software slow log adds the Complexity info field to the output data.

View the complexity info data by its respective command in the table below:

CommandValue of interestComplexity
LINSERTN - list lenO(N)
LREMN - list lenO(N)
LTRIMN - number of removed elementsO(N)
PUBLISHN - number of channel subscribers</br>M - number of subscribed patternsO(N+M)
PSUBSCRIBEN - number of patterns client is subscribed to</br>argc - number of arguments passed to the commandO(argc*N)
PUNSUBSCRIBEN - number of patterns client is subscribed to</br>M - total number of subscribed patterns</br>argc - number of arguments passed to the commandO(argc*(N+M))
SDIFFN - total number of elements in all setsO(N)
SDIFFSTOREN - total number of elements in all setsO(N)
SINTERN - number of elements in smallest set</br>argc - number of arguments passed to the commandO(argc*N)
SINTERSTOREN - number of elements in smallest set</br>argc - number of arguments passed to the commandO(argc*N)
SMEMBERSN - number of elements in a setO(N)
SORTN - number of elements in the when no sorting list/set/zset</br>M - number of elements in resultO(N+M*log(M))O(N)
SUNIONN - number of elements in all setsO(N)
SUNIONSTOREN - number of elements in all setsO(N)
UNSUBSCRIBEN - total number of clients subscribed to all channelsO(N)
ZADDN - number of elements in the zsetO(log(N))
ZCOUNTN - number of elements in the zset</br>M - number of elements between min and maxO(log(N)+M)
ZINCRBYN - number of elements in the zsetO(log(N))
ZINTERSTOREN – number of elements in the smallest zset</br>K – number of zsets</br>M – number of elements in the results setO(N*K)+O(M*log(M))
ZRANGEN – number of elements in the zset</br>M – number of resultsO(log(N)+M)
ZRANGEBYSCOREN – number of elements in the zset</br>M – number of resultsO(log(N)+M)
ZRANKN – number of elements in the zsetO(log(N))
ZREMN – number of elements in the zset</br>argc – number of arguments passed to the commandO(argc*log(N))
ZREMRANGEBYRANKN – number of elements in the zset</br>argc – number of arguments passed to the commandO(log(N)+M)
ZREMRANGEBYSCOREN – number of elements in the zset</br>M – number of elements removedO(log(N)+M)
ZREVRANGEN – number of elements in the zset</br>M – number of resultsO(log(N)+M)
ZREVRANKN – number of elements in the zsetO(log(N))
ZUNIONSTOREN – sum of element counts of all zsets</br>M – element count of resultO(N)+O(M*log(M))

View slow log

To view slow log entries for Redis Software databases, use one of the following methods:

  • Cluster Manager UI:

    1. To access the slow log in the Cluster Manager UI, your [cluster management role]({{<relref "/operate/rs/7.8/security/access-control/create-cluster-roles">}}) must be Admin, Cluster Member, or DB Member.

    2. Select a database from the Databases list.

    3. On the database's Configuration screen, select the Slowlog tab.

  • Command line:

    Use [redis-cli]({{<relref "/operate/rs/7.8/references/cli-utilities/redis-cli">}}) to run [SLOWLOG GET]({{<relref "/commands/slowlog-get">}}):

    sh
    redis-cli -h <endpoint> -p <port> SLOWLOG GET <count>
    

Change slow log threshold

The slow log includes all database commands that take longer than ten milliseconds (10,000 microseconds) by default. You can use [redis-cli]({{<relref "/operate/rs/7.8/references/cli-utilities/redis-cli">}}) to view or change this threshold.

To check the current threshold, run [CONFIG GET]({{<relref "/commands/config-get">}}):

sh
redis-cli -h <endpoint> -p <port> CONFIG GET slowlog-log-slower-than

To change the threshold, run [CONFIG SET]({{<relref "/commands/config-set">}}):

sh
redis-cli -h <endpoint> -p <port> CONFIG SET slowlog-log-slower-than <value_in_microseconds>

Change maximum entries

The slow log retains the last 128 entries by default. You can use [redis-cli]({{<relref "/operate/rs/7.8/references/cli-utilities/redis-cli">}}) to view or change the maximum number of entries.

To check the current maximum, run [CONFIG GET]({{<relref "/commands/config-get">}}):

sh
redis-cli -h <endpoint> -p <port> CONFIG GET slowlog-max-len

To change the maximum, run [CONFIG SET]({{<relref "/commands/config-set">}}):

sh
redis-cli -h <endpoint> -p <port> CONFIG SET slowlog-max-len <value>