当前位置:网站首页>Troubleshooting of high memory usage of redis in a production environment
Troubleshooting of high memory usage of redis in a production environment
2022-07-05 11:44:00 【We've been on the road】
The server goes online after a regular release , It is found that the cache expiration speed is much lower than the configured 10min Be overdue .
The phenomenon : Just logged into the system background , After that 1 The cache expires in minutes , Unable to log in to the background , Enter Alibaba cloud redis The server , Found logged in key period , During this period, I also encountered various strange problems , Inexplicably log in to the system, but later drop the line , Later, I went to Alibaba cloud and found redis Memory Take up as much as 100%. I guessed that there might be threads in a large number of write caches , And then put redis The space is full , because redis The server configuration is volatile-lru Strategy : When the memory is full , There are a lot of cache writes , Just delete Set expiration time Of key Medium It hasn't been used for the longest time recently Of key.

Then I ran to redis The server puts the current rdb( memory dump ) Download a copy locally to analyze what it is key Writing data crazily , Found this key, I can find and use this in the program key Code for , And then do the corresponding processing .
Log in to Alibaba cloud , Go to the latest backup

1、 Download to a full volume key Of rdb file

Then execute the following command to install python2.7 And load rdb plug-in unit , Generate csv file .
2、 Put this rdb Files use rdbTools Turn it into csv file .
-
pip install rdb
# install rdb
-
rdb -c memory hins8714399_data_20191015223705.rdb > memory.csv
# take redis Memory snapshot file , Store in csv In the document

3、 Will change csv Documents can be imported directly into mysql In the database , And then use mysql Query for , You can find out the one with the largest memory consumption key

Be careful A little bit is adopt csv Import mysql The default generated field types are varchar, We need to change the type here to int type , Used for sorting queries .

4、mysql There's a memory library , And then execute
SELECT * from memory ORDER BY size_in_bytes desc LIMIT 0, 10
According to the use of memory from large to small , Before the memory is occupied 10 Of key

Found these expired on null Of key, Find out The code does not address these key Set expiration time , It's permanent key, Some more redis Set the queue for consumption , Write a lot of data to the queue that never expires , Then the consumption thread only 2 individual , It's faster to add to the queue , Queue consumption is slow , Backstage I put consumption redis The thread of the queue is set to 20、10、5 Find an optimal number of threads ,CPU The occupation is not too high , The queue is not stacked 、 Make full use of the performance of the machine , Solve the actual needs .
summary : Through a toss , Learned how to parse redis Of rdb Snapshot file , analysis redis Distribution of memory , Memory footprint , that key Take up a lot of , that key Account for less , There is also a memory elimination strategy , Why this key Expire first , The other one will expire later .
Expand 1: Interested students can check more redis Memory retirement strategy
- volatile-lru: Pick the least recently used data from the memory data set with expiration time Eliminate ;
- volatile-ttl: Select the data about to expire from the memory data set with the expiration time Eliminate ;
- volatile-random: Pick any data from the memory data set with the expiration time set Eliminate ;
- allkeys-lru: Pick the least recently used data from the memory data set Eliminate ;
- allkeys-random: Pick any data from the data set Eliminate ;
- no-enviction( deportation ): Exclusion data .( Default elimination strategy . When redis Memory data reaches maxmemory, Under this strategy , Go straight back to OOM error );
About maxmemory Set up , By means of redis.conf in maxmemory Parameter setting , Or by order CONFIG SET Dynamic modification
About the setting of data elimination strategy , By means of redis.conf Medium maxmemory-policy Parameter setting , Or by order CONFIG SET Dynamic modification
</article>
边栏推荐
- What does cross-border e-commerce mean? What do you mainly do? What are the business models?
- 12.(地图数据篇)cesium城市建筑物贴图
- Open3D 网格(曲面)赋色
- 12. (map data) cesium city building map
- yolov5目標檢測神經網絡——損失函數計算原理
- Liunx prohibit Ping explain the different usage of traceroute
- Go language learning notes - first acquaintance with go language
- Acid transaction theory
- [configuration method of win11 multi-user simultaneous login remote desktop]
- 871. Minimum Number of Refueling Stops
猜你喜欢

技术管理进阶——什么是管理者之体力、脑力、心力

【yolov3损失函数】

pytorch-softmax回归

7 大主题、9 位技术大咖!龙蜥大讲堂7月硬核直播预告抢先看,明天见
![[upsampling method opencv interpolation]](/img/6b/5e8f3c2844f0cbbbf03022e0efd5f0.png)
[upsampling method opencv interpolation]

Splunk configuration 163 mailbox alarm

【L1、L2、smooth L1三类损失函数】

Ziguang zhanrui's first 5g R17 IOT NTN satellite in the world has been measured on the Internet of things
![[yolov5.yaml parsing]](/img/ae/934f69206190848ec3da10edbeb59a.png)
[yolov5.yaml parsing]

【使用TensorRT通过ONNX部署Pytorch项目】
随机推荐
Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in
Solve readobjectstart: expect {or N, but found n, error found in 1 byte of
【pytorch 修改预训练模型:实测加载预训练模型与模型随机初始化差别不大】
汉诺塔问题思路的证明
[mainstream nivida graphics card deep learning / reinforcement learning /ai computing power summary]
【主流Nivida显卡深度学习/强化学习/AI算力汇总】
C # implements WinForm DataGridView control to support overlay data binding
基于Lucene3.5.0怎样从TokenStream获得Token
2048 game logic
[LeetCode] Wildcard Matching 外卡匹配
7.2 daily study 4
【yolov5.yaml解析】
Solve the grpc connection problem. Dial succeeds with transientfailure
百问百答第45期:应用性能探针监测原理-node JS 探针
c#操作xml文件
1.php的laravel创建项目
COMSOL -- three-dimensional graphics random drawing -- rotation
以交互方式安装ESXi 6.0
C operation XML file
pytorch-权重衰退(weight decay)和丢弃法(dropout)