当前位置:网站首页>Redis 排查大 key 的4種方法,優化必備
Redis 排查大 key 的4種方法,優化必備
2022-07-06 04:37:00 【Java筆記蝦】
摘要:在日常Redis的使用中,難免遇到因為 key 存儲了過大的數據而造成請求緩慢甚至阻塞的情况,這個時候就需要排查 Redis 的大key去優化業務了,下面提供一些排查方案總結,僅供參考。
一、多大的 key 算大呢?
Redis 實踐總結(僅供參考):
合理的 Key 中 Value 的字節大小,推薦小於 10 KB。
過大的 Value 會引發數據傾斜、熱點Key、實例流量或 CPU 性能被占滿等問題,應從設計源頭上避免此類問題帶來的性能影響。
那麼 value Bytes > 10 kb 可以作為判斷 大 key 的一個參考值。
二、排查大 key 的方法
1、使用命令 --bigkeys
--bigkeys
是 redis 自帶的命令,對整個 Key 進行掃描,統計 string,list,set,zset,hash 這幾個常見數據類型中每種類型裏的最大的 key。
string 類型統計的是 value 的字節數;另外 4 種複雜結構的類型統計的是元素個數,不能直觀的看出 value 占用字節數,所以 --bigkeys 對分析 string 類型的大 key 是有用的,而複雜結構的類型還需要一些第三方工具。
注:元素個數少,不一定 value 不大;元素個數多,也不一定 value 就大
redis-cli -h 127.0.0.1 -p 6379 -a "password" --bigkeys
--bigkeys
是以 scan 延遲計算的方式掃描所有 key,因此執行過程中不會阻塞 redis,但實例存在大量的 keys 時,命令執行的時間會很長,這種情况建議在 slave 上掃描。
–-bigkeys
其實就是找出類型中最大的 key,最大的 key 不一定是大 key,最大的 key 都不超過 10kb 的話,說明不存在大 key。
但某種類型如果存在較多的大key (>10kb),只會統計 top1 的那個 key,如果要統計所有大於 10kb 的 key,需要用第三方工具掃描 rdb 持久化文件。
2、使用 memory 命令查看 key 的大小(僅支持 Redis 4.0 以後的版本)
redis-cli -h 127.0.0.1 -p 6379 -a password
MEMORY USAGE keyname1
(integer) 157481
MEMORY USAGE keyname2
(integer) 312583
3、使用 Rdbtools 工具包
Rdbtools 是 python寫的 一個第三方開源工具,用來解析 Redis 快照文件。除了解析 rdb 文件,還提供了統計單個 key 大小的工具。
1、安裝
git clone https://github.com/sripathikrishnan/redis-rdb-tools
cd redis-rdb-tools sudo && python setup.py install
2、使用
從 dump.rdb
快照文件統計, 將所有 > 10kb 的 key 輸出到一個 csv 文件
rdb dump.rdb -c memory --bytes 10240 -f live_redis.csv
4、使用 go-redis-bigkv
go-redis-bigkv 是本人開發的一個小工具。主要是 基於 memory 命令,掃描 redis 中所有的 key,並將結果按照 內存大小進行排序,並將排序後的 結果輸出到 txt 文件中。因為是 以 scan 延遲計算的方式掃描所有 key,因此執行過程中不會阻塞 redis,但實例存在大量的 keys 時,命令執行的時間會很長。
項目地址:
https://github.com/th3ee9ine/go-redis-bigk
推薦:
最全的java面試題庫
PS:因為公眾號平臺更改了推送規則,如果不想錯過內容,記得讀完點一下“在看”,加個“星標”,這樣每次新文章推送才會第一時間出現在你的訂閱列錶裏。點“在看”支持我們吧!
边栏推荐
- Tengine kernel parameters
- [FreeRTOS interrupt experiment]
- CADD course learning (8) -- virtual screening of Compound Library
- 8. Static file
- Yyds dry inventory automatic lighting system based on CC2530 (ZigBee)
- 我想问一下 按照现在mysql-cdc的设计,全量阶段,如果某一个chunk的binlog回填阶段,
- Coreldraw2022 new version new function introduction cdr2022
- P2102 地砖铺设(dfs&贪心)
- One question per day (Mathematics)
- The value of two date types is subtracted and converted to seconds
猜你喜欢
Slow SQL fetching and analysis of MySQL database
Practical development of member management applet 06 introduction to life cycle function and user-defined method
Certbot failed to update certificate solution
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (柔性对接 AutoDock)
Distributed transaction solution
In depth MySQL transactions, stored procedures and triggers
Easyrecovery reliable and toll free data recovery computer software
捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统
Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization
随机推荐
【HBZ分享】ArrayList的增删慢查询快的原因
Fedora/rehl installation semanage
Mixed development of QML and QWidget (preliminary exploration)
Stable Huawei micro certification, stable Huawei cloud database service practice
P2022 interesting numbers (binary & digit DP)
动态规划(树形dp)
1008 circular right shift of array elements (20 points)
It is also a small summary in learning
2327. Number of people who know secrets (recursive)
P3500 [poi2010]tes intelligence test (two points & offline)
解决“C2001:常量中有换行符“编译问题
[face recognition series] | realize automatic makeup
C. The third problem
Visio draws Tai Chi
Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps
JVM garbage collector concept
Etcd database source code analysis -- etcdserver bootstrap initialization storage
Recommendation | recommendation of 9 psychotherapy books
P2102 floor tile laying (DFS & greed)
word封面下划线