A redis OOM problem analysis and solution, rdbtools installation analysis redis memory

 

It is inevitable to encounter more embarrassing projects. The quality is really messy, and the use of redis is also messy. Then there will be a problem. What should I do if the memory can't support it?

Not high availability, only one naked redis (high availability plan will be discussed next time)

table of Contents

Analysis steps

OOM emergency solution:

How to find the big key

Install rdbtools

Use redis-rdb-tools to generate a memory snapshot:


Analysis steps

Enter redis, view memory usage

redis -a 密码
info memory

The server allocates 5G memory, maxmemory is 5G, and 4.66G is available, and it is all used up when OOM occurs; for detailed analysis, you can specifically ask the next mother

 

OOM emergency solution :

Increase the maximum memory, config set maxmemory xxx

Set memory elimination strategy: I set it to allkeys-lru

Redis5.0 defines several strategies to deal with this situation:

(1) Volatile-lru: Select the least recently used data from the data set with the expiration time set and eliminate it.

(2) Volatile-ttl: Select the data to be expired from the data set with the expiration time set.

(3) Volatile-random: arbitrarily select data to be eliminated from the data set that has set expiration time.

(4) Volatile-lfu: Select the least frequently used data from the data set with the expiration time set and eliminate it.

(5) allkeys-lru: select the least recently used data from the data set to eliminate

(6) allkeys-lfu: select the least frequently used data from the data set and eliminate it.

(7) allkeys-random: arbitrarily select data to eliminate from the data set (server.db[i].dict)

(8) no-enviction (eviction): prohibits eviction of data, this is also the default strategy. This means that when the memory is insufficient to accommodate the new data, the new write operation will report an error, the request can continue, and the online task cannot continue. The no-enviction strategy can ensure that the data is not lost.

These eight types can be roughly divided into 4 categories, lru, lfu, random, and ttl.

 

When using the three strategies of volatile-lru, volatile-random, and volatile-ttl, if no key can be eliminated, an error will be returned like noeviction


But this is only a temporary solution, you need to know what the root cause is

Question: Why is 5G not enough? There must be a big key, or too much use, no expiration time is set

Okay, 1. Find out the big key, 2. Reduce unnecessary cache, 3. You must set the expiration time

 

How to find the big key

I searched the Internet for a long time for useful tools, useful python, useful commands; if you are interested, you can read this article: https://www.cnblogs.com/yqzc/p/12425533.html

Here I introduce it is quite convenient to analyze with rdbtools

Install rdbtools

pip install rdbtools install

If pip is not installed, install pip, please see the tutorial: https://blog.csdn.net/Goligory/article/details/106033972

 

git clone https://github.com/sripathikrishnan/redis-rdb-tools

cd redis-rdb-tools

python3 setup.py install

Install as follows 

Use redis-rdb-tools to generate a memory snapshot:

rdb -c memory dump.rdb > memory.csv

Dump.rdb may not be found at this time

Solution:

Log in to redis

Command: save

Command (find the installation directory): config get dir

Exit, cd to the installation directory and you will see dump.rdb

Execute in the dump.rdb directory: rdb -c memory dump.rdb> memory.csv, the csv file is in the current folder, you can export it to view directly, the effect is as follows

 

You can also use SQLite to analyze csv files. I won’t talk about it here. If you are interested, you can ask Du Niang

 

 

 

Reference: https://www.cnblogs.com/aresxin/p/9014617.html

 

Guess you like

Origin blog.csdn.net/Goligory/article/details/106033551