当前位置:网站首页>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:因為公眾號平臺更改了推送規則,如果不想錯過內容,記得讀完點一下“在看”,加個“星標”,這樣每次新文章推送才會第一時間出現在你的訂閱列錶裏。點“在看”支持我們吧!边栏推荐
- Word cover underline
- Dynamic programming (tree DP)
- Ue5 small knowledge points to enable the setting of lumen
- P3500 [poi2010]tes intelligence test (two points & offline)
- Stable Huawei micro certification, stable Huawei cloud database service practice
- Canal synchronizes MySQL data changes to Kafka (CentOS deployment)
- VPP性能测试
- hashlimit速率控制
- Basic use of MySQL (it is recommended to read and recite the content)
- One question per day (Mathematics)
猜你喜欢

Visio draws Tai Chi

Database - MySQL storage engine (deadlock)
![[detailed steps of FreeRTOS shift value for the first time]](/img/73/a469eb2465bb2c5acaa4d018d3edd3.jpg)
[detailed steps of FreeRTOS shift value for the first time]

Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization

电脑钉钉怎么调整声音

The most detailed and comprehensive update content and all functions of guitar pro 8.0

Introduction to hashtable

8. Static file

Fedora/rehl installation semanage

Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
随机推荐
1291_ Add timestamp function in xshell log
[network] channel attention network and spatial attention network
[face recognition series] | realize automatic makeup
During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input
canal同步mysql数据变化到kafka(centos部署)
729. 我的日程安排表 I(set or 动态开点线段树)
C'est un petit résumé de l'étude.
Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps
Implementation of knowledge consolidation source code 1: epoll implementation of TCP server
[HBZ sharing] how to locate slow queries in cloud database
Coreldraw2022 new version new function introduction cdr2022
MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0
Visio draws Tai Chi
Ue5 small knowledge freezerendering view rendered objects in the cone
Mixed development of QML and QWidget (preliminary exploration)
P2022 有趣的数(二分&数位dp)
Cross domain and jsonp details
Recommendation system (IX) PNN model (product based neural networks)
Stable Huawei micro certification, stable Huawei cloud database service practice
Recommendation | recommendation of 9 psychotherapy books