Talking about the slow query log of Redis

Source: Internet
Author: User
Tags redis server

First we need to know what is the use of the slow query log for Redis? Why use a slow query log when using Redis everyday?

First question:

The slow query log is to record the execution time over a timed Redis command request

Second question:

Allow users to better monitor and identify some slow redis operations in the business and find better ways to optimize

In Redis, there are two settings for slow queries-the maximum time- out for slow queries and the maximum number of logs for slow queries.

1. You can set the time limit for slow queries by modifying the configuration file or by entering the following command directly in interactive mode, and when this time is exceeded, the records of the query are added to the log file.

CONFIG SET Slowlog-log-slower-than num

Setting more than a few subtle queries for slow queries, and adding these slow queries to the log file, num is in milliseconds, and the default slow query for Redis under Windows is 10000 subtle 10 milliseconds.

2. You can set the maximum number of slow query logs saved in the log by setting the command in interactive mode as follows:

CONFIG SET Slowlog-max-len num

Set the maximum number of logs, num no unit value, and the number of records for redis default slow query log under Windows is 128.

Parsing of commands:

The CONFIG command causes the Redis client to look for Redis's. conf configuration file and locate the corresponding configuration item for modification.

The above is the configuration of Redis in interactive mode, and directly under the. conf file to modify the configuration line is not the difference, can achieve the above slow query logging function,

However, it is important to note that the Config set command is entered in the interactive mode of the client, only for the current session to perform logging settings, and the other sessions (restart

Redis server), then still the same, according to the default settings of the redis.conf file to execute? Why would it be like that? Because Redis is memory-based, when one exits a

After the client, all settings are returned to the default version. The next time you want to set a slow query log configuration, you still need to retype the command. What about modifying the configuration under the. conf file?

This approach is relatively permanent, because each server start is based on the configuration file, so the Slowlog log will default to the settings in the. conf file as standard.

Even so, when it comes to testing, individuals prefer to modify directly in interactive mode, and modify in interactive mode to enable Redis clients in the current state and later

(under the condition that the server has not yet restarted), the logging function of the slow query log will be performed. If you modify the configuration item in the. conf file, you will need to restart the Redis server.

To make this function effective, the next time you need to modify the configuration, you will also get the. conf file to reconfigure.

For a more complete description of the profile process, I'll write here how to modify the configuration item in the. conf file

Windows operating system under Notepad, Linux operating system with Sublim text or vim open. Found it

The following will find the configuration options

So next, how do you see slow queries?

Again into interactive mode, the command is simple.

Slowlog GET

(Of course, you can also use lowercase, redis clients are not too restrictive on capitalization)

Take windows as an example to view the records below

For illustrative purposes, I set the timeout to 0 milliseconds, logging to 1

What is the difference between 1 of the records and 2) 3) 4)?

1) indicates the log unique identifier UID

2) time stamp of the system when the command executes

3) The length of the command execution, measured in a subtle

4) parameters of commands and commands

When you do log queries, you can check the command run time by 3) (note: Once again, the unit of time is subtle, but for an insert operation,

10000 subtle, that is, 10 milliseconds is 0.01 seconds can be considered slow operation of what the operation is a problem. Of course this is limited to testing use if required when the business appears Redis

Inserting slow-query events requires you to look at the persistent logs generated by Redis, which requires additional configuration of the content, which involves clustering and distribution, which is donuts first.

I hope that I will have a deeper understanding of the time to write again the relevant articles.

Talking about the slow query log of Redis

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.