当前位置:网站首页>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:因為公眾號平臺更改了推送規則,如果不想錯過內容,記得讀完點一下“在看”,加個“星標”,這樣每次新文章推送才會第一時間出現在你的訂閱列錶裏。點“在看”支持我們吧!边栏推荐
- How to realize automatic playback of H5 video
- 【HBZ分享】ArrayList的增删慢查询快的原因
- HotSpot VM
- How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server
- . Net interprocess communication
- SharedPreferences 源码分析
- In depth MySQL transactions, stored procedures and triggers
- 满足多元需求:捷码打造3大一站式开发套餐,助力高效开发
- P2022 有趣的数(二分&数位dp)
- VNCTF2022 WriteUp
猜你喜欢

Overturn your cognition? The nature of get and post requests

CADD course learning (8) -- virtual screening of Compound Library

Lombok原理和同时使⽤@Data和@Builder 的坑

Is the mode of education together - on campus + off campus reliable

Etcd database source code analysis -- etcdserver bootstrap initialization storage

During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input

Figure application details

MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0
![[detailed steps of FreeRTOS shift value for the first time]](/img/73/a469eb2465bb2c5acaa4d018d3edd3.jpg)
[detailed steps of FreeRTOS shift value for the first time]

When debugging after pycharm remote server is connected, trying to add breakpoint to file that does not exist: /data appears_ sda/d:/segmentation
随机推荐
动态规划(树形dp)
Lombok原理和同时使⽤@Data和@Builder 的坑
Selection of slow motion function
web工程导入了mysql驱动jar包却无法加载到驱动的问题
[HBZ share] reasons for slow addition and deletion of ArrayList and fast query
How does vs change the project type?
Digital children < daily question> (Digital DP)
2327. Number of people who know secrets (recursive)
1291_ Add timestamp function in xshell log
【Try to Hack】john哈希破解工具
Ue5 small knowledge freezerendering view rendered objects in the cone
Complete list of common functions of turtle module
Deep learning framework installation (tensorflow & pytorch & paddlepaddle)
One question per day (Mathematics)
电脑钉钉怎么调整声音
Tengine kernel parameters
Explain in simple terms node template parsing error escape is not a function
Stable Huawei micro certification, stable Huawei cloud database service practice
ue5 小知识 FreezeRendering 查看视锥内渲染的物体
Yyds dry inventory automatic lighting system based on CC2530 (ZigBee)