当前位置:网站首页>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:因为公众号平台更改了推送规则,如果不想错过内容,记得读完点一下“在看”,加个“星标”,这样每次新文章推送才会第一时间出现在你的订阅列表里。点“在看”支持我们吧!边栏推荐
- Microservice resource address
- VNCTF2022 WriteUp
- [Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity
- 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
- The most detailed and comprehensive update content and all functions of guitar pro 8.0
- About some basic DP -- those things about coins (the basic introduction of DP)
- MySQL reported an error datetime (0) null
- Mysql数据库慢sql抓取与分析
- QML和QWidget混合开发(初探)
- [network] channel attention network and spatial attention network
猜你喜欢

Use sentinel to interface locally

Etcd database source code analysis -- etcdserver bootstrap initialization storage
![[network] channel attention network and spatial attention network](/img/b5/5e746f0dd6badcf0714cae05fc6e82.jpg)
[network] channel attention network and spatial attention network

VNCTF2022 WriteUp

Distributed transaction solution

Coreldraw2022 new version new function introduction cdr2022

DMA use of stm32
![[face recognition series] | realize automatic makeup](/img/a5/de98d0522b9dae809cd242aac305b3.jpg)
[face recognition series] | realize automatic makeup

Easyrecovery reliable and toll free data recovery computer software

ue5 小知识点 开启lumen的设置
随机推荐
Dry goods collection | Vulkan game engine video tutorial
Bubble sort
Stable Huawei micro certification, stable Huawei cloud database service practice
How do programmers teach their bosses to do things in one sentence? "I'm off duty first. You have to work harder."
The most detailed and comprehensive update content and all functions of guitar pro 8.0
. Net interprocess communication
Platformio create libopencm3 + FreeRTOS project
11. Intranet penetration and automatic refresh
SQL注入漏洞(MSSQL注入)
Deep learning framework installation (tensorflow & pytorch & paddlepaddle)
Sqlserver query results are not displayed in tabular form. How to modify them
Selection of slow motion function
P2102 floor tile laying (DFS & greed)
word封面下划线
[HBZ sharing] how to locate slow queries in cloud database
Fedora/rehl installation semanage
cdc 能全量拉去oracle 表嘛
hashlimit速率控制
web工程导入了mysql驱动jar包却无法加载到驱动的问题
Data processing methods - smote series and adasyn