learning redis - Advanced Features

Other more basic articles java:
java based learning (directory)


Slow query

Learning materials
redis advanced features - slow query

Two configuration parameters slow queries

Redis provided slowlog-log-slower-thanand slowlog-max-lenconfigured to solve these two problems. Can be seen from the literal meaning, slowlog-log-slower-thanis this preset threshold, its unit is microsecond (1 second = 1 million microseconds) The default value is 10000 , if the implementation of a " very slow "command (for example, key *), if the execution time of more than 10,000 microseconds, it will be recorded in the slow query log.

If slowlog-log-slower-than=0records all commands, slowlog-log-slower-than<0any command will not be recorded.

In fact Redis uses a list to store the slow query log, slowlog-max-lenthe maximum length of that list. Was inserted into this list when a new order to meet the slow query, when the slow query log list is at its maximum length, the insertion of the earliest a command is removed from the list, for example, slowlog-max-lenis provided with a length of 64. when article 65 is inserted slow query log, then the first data queue head on the column, article 65 will slow query into the column.

There are two ways to modify the configuration of the Redis,

  • One is to modify the configuration file
  • Another is to use the config set command to dynamically modify

The following example using the config set command slowlog-log-slower-than 20,000 to subtle .slowlog-max-len to 1024:

    config set slowlog-log-slower-than 20000
    config set slowlog-max-len 1024
    config rewrite
复制代码

Practice summary

Slow query function can effectively help us find Redis bottlenecks that may exist, but in actual use should note the following:

  1. slowlog-max-len: Online is recommended to transfer large slow query list, Redis command will do long stage operation record slow queries, and will not take up a lot of memory can be reduced to increase the list of slow queries slow query may be removed, for example, the line can be set. 1000 or more.

  2. slowlog-log-slower-than: The default value of more than 10 ms is determined slow queries, need to adjust the value according to the amount due Redis Redis concurrent single-threaded appropriate command, for high traffic scenario, if the execution time exceeds the command. 1 above ms, then up Redis not support OPS to 1000 so for Redis OPS scene at a high recommendation to 1 millisecond.

  3. Slow query execution time only recording command does not include command queuing and network transmission time. Therefore, the client command execution time will be greater than the actual execution time of the command. Because the command queuing, slow query can lead to a cascade blocking other commands, Therefore, when a client requests a timeout occurs, you need to check this point in time there is a corresponding slow queries to analyze whether the slow query command causes a cascade of obstruction.

  4. Due to the slow query log is a FIFO queue, ie if more slow query case, may lose some slow query command, in order to prevent this from happening, you can perform periodic slowlog getcommand will persist to the slow query log other storage (eg: MySQL, elasticSearch etc.), and can be queried by visualization tools.

pipline and Services

Learning materials
redis study notes - Pipeline transaction

Publish and subscribe

Learning materials
Redis subscriptions to the publication - Jedis achieved
in several ways from shallow to deep [] publish subscription achieve redis

Bitmap/Hyperloglog/Geo

Learning materials
availability Redis (six): the Swiss Army knife of the bitmap, HyperLoglog and GEO
Redis with setbit (bitmap) Statistics Active Users

Guess you like

Origin juejin.im/post/5d85e079e51d4561eb0b2757