Redis Log System

Source: Internet
Author: User
Today, the middleware interface has a long response time. After a rough investigation, it is found that access to Redis is slow, and the Redis cpu has indeed reached about 98%. Now you need to locate the problem. Open it first.

Today, the middleware interface has a long response time. After a rough investigation, it is found that access to Redis is slow, and the Redis cpu has indeed reached about 98%. Now you need to locate the problem. Open it first.

Today, the middleware interface has a long response time. After a rough investigation, it is found that access to Redis is slow, and the Redis cpu has indeed reached about 98%. Now you need to locate the problem and open the redis slowlog first.

What is SLOWLOG?

Slow log is the log system used by Redis to record the query execution time.

The query execution time does not include I/O operations such as client response (talking) and reply sending, but is the time consumed by executing a query command.

In addition, the slow log is saved in the memory, and the read/write speed is very fast. Therefore, you can use it with confidence, so you do not have to worry about compromising the Redis speed because slow log is enabled.

The Slow log behavior is specified by two configuration parameters (configuration parameter). You can modify them dynamically by rewriting the redis. conf file or using the CONFIG and CONFIG commands.

The first option is slowlog-log-slower-than, which determines how many microseconds (microsecond, 1 second = 1,000,000 microseconds) the execution time must be greater.

For example, execute the following command to record all queries whose query time is greater than or equal to 100 microseconds:

CONFIG setslowlog-log-slower-than 100

The following command records all queries with a query time greater than 1000 microseconds:

CONFIG setslowlog-log-slower-than 1000

Another option is slowlog-max-len, which determines the maximum number of logs that slow log can store. slow log itself is a LIFO queue. When the queue size exceeds slowlog-max-len, the oldest log will be deleted, and the newest log will be added to the slow log, and so on.

Run the following command to allow slow logs to store a maximum of 1000 logs:

CONFIG get slowlog-max-len

You can use the CONFIG command to query the current values of the two options:

View slow log

To view slow logs, run the slowlog get or slowlog get number command. The former prints all slow logs. The maximum length depends on the value of the slowlog-max-len option, SLOWLOG number prints only the specified number of logs.

The latest logs will be printed first:

The unique log id is reset only when the Redis server is restarted, this avoids repeated processing of logs (for example, you may want to send an email to you every time you find a new slow query ).

View the number of current logs

Run the SLOWLOG command to view the number of current logs.

Note the difference between this value and slower-max-len. One is the number of current logs and the other is the maximum number of logs allowed to be recorded.
Redis> SLOWLOG LEN
(Integer) 14

Clear logs

Run the slowlog reset command to clear the slow log.
Redis> SLOWLOG LEN
(Integer) 14

Redis> SLOWLOG RESET
Redis> SLOWLOG LEN
(Integer) 0

Through the slow log, you can find that the program uses the keys message _ * command, resulting in long middleware response time. modify the code and eliminate the problem.

You may also like the following articles about Redis. For details, refer:

Install and test Redis in Ubuntu 14.04

Basic configuration of Redis master-slave Replication

Redis cluster details

Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis

Redis series-installation, deployment, and maintenance

Install Redis in CentOS 6.3

Learning notes on Redis installation and deployment

Redis. conf

Redis details: click here
Redis: click here

This article permanently updates the link address:

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.