Home>Article>Database> Let me take you to carefully analyze the reasons why the redis expired key is not released!

Let me take you to carefully analyze the reasons why the redis expired key is not released!

藏色散人
藏色散人 forward
2022-12-20 13:53:14 2152browse

This article will introduce you to redis-related knowledge. The main content is to analyze the reasons why redis expired keys are not released. I hope it will be helpful to friends in need! Let’s take a look!

Background:

1, redis version 5.0;

2, 32G redis cloud server, the memory continues to increase, and the memory occupied by expired keys has not been freed. The memory usage is as follows:

Let me take you to carefully analyze the reasons why the redis expired key is not released!

Recent redis operation: 20 million never-expired keys were randomly assigned an expiration time of 7-20 days.

Optimization process:

1. Observe Alibaba Cloud’s “offline full key analysis” for several days;

2. Discover the memory of expired keys It has not been released and has increased from 2G to 5G;

3. Analyze the reason why the expired key memory is not released;

4. Adjust the hz parameter of redis from 10 to 30 and find no change;

5. Analyze redis source code.

6. Conclusion: Reason for redis memory not being released: Recently, 20 million keys have been set to expire, resulting in a garbage collection hit rate less than 25%, and expired keys will not be cycled repeatedly. (Source code file: expire.c, activeExpireCycle function).

Let me take you to carefully analyze the reasons why the redis expired key is not released!

hz Description [Recommended learning:redis video tutorial]

Let me take you to carefully analyze the reasons why the redis expired key is not released!

7. Final processing Method: No operation is required. As the number of expired keys increases and the hit rate increases, the memory will eventually be released. (If you want to speed up the process, set the "hz" parameter to a larger value, which is faster, but will consume more CPU resources. Please refer to the Alibaba Cloud documentation).

Let me take you to carefully analyze the reasons why the redis expired key is not released!

The above is the detailed content of Let me take you to carefully analyze the reasons why the redis expired key is not released!. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete