当前位置:网站首页>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) 3125833、使用 Rdbtools 工具包
Rdbtools 是 python寫的 一個第三方開源工具,用來解析 Redis 快照文件。除了解析 rdb 文件,還提供了統計單個 key 大小的工具。
1、安裝
git clone https://github.com/sripathikrishnan/redis-rdb-tools
cd redis-rdb-tools sudo && python setup.py install2、使用
從 dump.rdb 快照文件統計, 將所有 > 10kb 的 key 輸出到一個 csv 文件
rdb dump.rdb -c memory --bytes 10240 -f live_redis.csv4、使用 go-redis-bigkv
go-redis-bigkv 是本人開發的一個小工具。主要是 基於 memory 命令,掃描 redis 中所有的 key,並將結果按照 內存大小進行排序,並將排序後的 結果輸出到 txt 文件中。因為是 以 scan 延遲計算的方式掃描所有 key,因此執行過程中不會阻塞 redis,但實例存在大量的 keys 時,命令執行的時間會很長。
項目地址:
https://github.com/th3ee9ine/go-redis-bigk
推薦:
最全的java面試題庫
PS:因為公眾號平臺更改了推送規則,如果不想錯過內容,記得讀完點一下“在看”,加個“星標”,這樣每次新文章推送才會第一時間出現在你的訂閱列錶裏。點“在看”支持我們吧!边栏推荐
- 【HBZ分享】云数据库如何定位慢查询
- SQL注入漏洞(MSSQL注入)
- 牛顿插值法
- 2327. 知道秘密的人数(递推)
- How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server
- P2102 地砖铺设(dfs&贪心)
- ue5 小知识 FreezeRendering 查看视锥内渲染的物体
- npm命令--安装依赖包--用法/详解
- Implementation of knowledge consolidation source code 2: TCP server receives and processes half packets and sticky packets
- 拉格朗日插值法
猜你喜欢
![[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity](/img/ac/93a64e59592e3d083a771b993d6884.jpg)
[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity

The value of two date types is subtracted and converted to seconds

Practical development of member management applet 06 introduction to life cycle function and user-defined method

CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)

Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps

Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022

MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】

How to realize automatic playback of H5 video

Certbot failed to update certificate solution
![Mlapi series - 04 - network variables and network serialization [network synchronization]](/img/fc/aebbad5295481788de5c1fdb432a77.jpg)
Mlapi series - 04 - network variables and network serialization [network synchronization]
随机推荐
Uva1592 Database
[face recognition series] | realize automatic makeup
Easyrecovery reliable and toll free data recovery computer software
Query the number and size of records in each table in MySQL database
【Try to Hack】john哈希破解工具
8. Static file
1291_ Add timestamp function in xshell log
About some basic DP -- those things about coins (the basic introduction of DP)
[05-1, 05-02, 05-03] network protocol
hashlimit速率控制
729. 我的日程安排表 I(set or 动态开点线段树)
CADD course learning (8) -- virtual screening of Compound Library
Platformio create libopencm3 + FreeRTOS project
[Zhao Yuqiang] deploy kubernetes cluster with binary package
也算是学习中的小总结
Yyds dry inventory automatic lighting system based on CC2530 (ZigBee)
[Yu Yue education] reference materials of complex variable function and integral transformation of Northwestern Polytechnic University
[detailed steps of FreeRTOS shift value for the first time]
【HBZ分享】云数据库如何定位慢查询
Mysql数据库慢sql抓取与分析