Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of slow query Operation in Redis

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail the example analysis of slow query operation in Redis. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

What is slow query?

The role of slow query: through slow query analysis, find problematic commands for optimization.

Like mysql's slow SQL log analysis, redis has similar features to help locate some slow query operations.

Redis slowlog is a logging system used by Redis to record the execution time of queries.

Query execution time refers to the time it takes to execute a query command, excluding IO operations such as client response (talking) and sending replies.

In addition, slow log is stored in memory and reads and writes very fast, so you can safely use it without having to worry about harming the speed of Redis by turning on slow log.

There are four attributes of slow query log:

1. The first field is a unique identity for each slow query.

2. Timestamp after processing the command

3. The time required to change the name of the execution is subtle.

4. The parameter list of the command, which is an array type

The ID of each slow query entity is unique and will not be reset. It will only be reset after redis restart.

Slow query parameters

First, let's take a look at the two parameters corresponding to the slow log analysis:

1. Slowlog-log-slower-than: the default threshold is 10000 microseconds, that is, 10 milliseconds, for how long a record is recorded.

2. Slowlog-max-len: record the number of slow queries. Default is 128.When the number of entries exceeds the set number, the earliest entry into the queue will be removed. It is recommended online to increase the value, such as 1000, to reduce the frequency of queue removal.

127.0.0.1) config get slowlog-log-slower-than1) "slowlog-log-slower-than" 2) "10000" 127.0.1) config get slowlog-max-len1) "slowlog-max-len" 2) "128"

You can adjust these two parameters with config set, or set them in a configuration file.

# # SLOW LOG # # The Redis Slow Log is a system to log queries that exceeded a specified# execution time. The execution time does not include the O operations# like talking with the client, sending the reply and so forth,# but just the time needed to actually execute the command (this is the only# stage of command execution where the thread is blocked and can not serve# other requests in the meantime). # # You can configure the slow log with two parameters: one tells Redis# what is the execution time, in microseconds, to exceed in order for the# command to get logged, and the other parameter is the length of the# slow log. When a new command is logged the oldest one is removed from the# queue of logged commands.# The following time is expressed in microseconds, so 1000000 is equivalent# to one second. Note that a negative number disables the slowlog, while# a value of zero forces the logging of every command.slowlog-log-slower-than 10000# There is no limit to this length. Just be aware that it will consume memory.# You can reclaim memory used by the slowlog with SLOWLOG RESET.slowlog-max-len 128

Slow query command

Syntax: slowlog subcommand [argument]

For example, perform slow query, obtain the number of slow query records, reset the slow query log, and so on:

192.168.10.38 slowlog get 9001 > empty list or set) 192.168.10.38 slowlog get 9001 > slowlog get 10 (empty list or set) 192.168.10.38 slowlog get 9001 > slowlog len (integer) 0192.168.10.38 slowlog len 9001 > slowlog resetOK on "sample analysis of slow query operations in Redis" is here. I hope the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good. Please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report