Redis feature--slow log details

Source: Internet
Author: User
Tags redis server

SLOWLOG subcommand [argument]

What is Slowlog

Slow log is a log system used by Redis to record query execution times.

Query execution time refers to not including IO operations such as client response (talking), sending replies, and simply the time spent executing a query command.

In addition, the slow log is stored in memory and reads and writes very quickly, so you can use it with confidence, without worrying about the speed of Redis due to opening slow log.

Set Slowlog

The behavior of Slow log is specified by two configuration parameters (config parameter) and can be dynamically modified by overwriting redis.conf files or by using CONFIG GET and CONFIG SET commands.

The first option is slowlog-log-slower-than that it determines how many microseconds (microsecond,1 seconds = 1,000,000 microseconds) of execution time are recorded for queries.

For example, executing the following command will let slow log log all queries that have a query time greater than or equal to 100 microseconds:

CONFIG SET slowlog-log-slower-than 100

The following command logs all queries that have a query time greater than 1000 microseconds:

CONFIG SET slowlog-log-slower-than 1000

Another option is slowlog-max-len that it determines how many logs slow log can hold, slow log itself is a FIFO queue, and when the queue size exceeds, the oldest slowlog-max-len log is deleted, and the latest log is added to the slow log to This analogy.

The following command allows slow log to save up to 1000 logs:

CONFIG SET slowlog-max-len 1000

Use CONFIG GET the command to query the current values of the two options:

redis> config get slowlog-log-slower-than1) "Slowlog-log-slower-than" 2) "$" redis> CONFIG get Slowlog-max-len1 ) "Slowlog-max-len" 2) "1000"

View Slow Log

To view slow log, you can use SLOWLOG GET or SLOWLOG GET number command to print all slow log, the maximum length depends on slowlog-max-len the value of the option, and SLOWLOG GET number only a specified number of logs are printed.

The most recent logs will be printed first:

# for Test needs, set Slowlog-log-slower-than to 10 microseconds redis> Slowlog GET1) 1) (integer)                      # Uniqueness (unique) log identifier   2) (integer ) 1324097834              # Execution time point of the recorded command, in UNIX timestamp format   3) (integer)                      # Query execution time, in microseconds of   4) 1) "CONFIG"                       # command executed, Arranged as an array of      2) "GET"                          # here is the complete command of CONFIG GET Slowlog-log-slower-than      3) "Slowlog-log-slower-than" 2) 1) (integer )   2) (integer) 1324097825   3) (integer)   4) 1) "CONFIG"      2) "GET"      3) "*" 3) 1) (integer) 10
   2) (integer) 1324097820   3) (integer)   4) 1) "CONFIG"      2) "GET"      3) "Slowlog-log-slower-than" # ...

The unique ID of the log is reset only when the Redis server restarts, which avoids repetitive processing of the log (for example, you might want to notify you when a new slow query is found).

View the current number of logs

Use SLOWLOG LEN the command to view the current number of logs.

Note the difference between this value and slower-max-len the number of the current log, and the maximum number of logs allowed to be logged.

redis> slowlog LEN (integer) 14

Empty log

Use the command SLOWLOG RESET to empty the slow log.

redis> slowlog len (integer) 14redis> slowlog resetokredis> slowlog len (integer) 0
Available versions:
>= 2.2.12
Complexity of Time:
O (1)
return value:
depending on the command, different values are returned.

Redis feature--slow log details

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.