当前位置:网站首页>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:因为公众号平台更改了推送规则,如果不想错过内容,记得读完点一下“在看”,加个“星标”,这样每次新文章推送才会第一时间出现在你的订阅列表里。点“在看”支持我们吧!边栏推荐
- . Net interprocess communication
- Lombok原理和同时使⽤@Data和@Builder 的坑
- 1291_ Add timestamp function in xshell log
- C. The Third Problem(找规律)
- Distributed transaction solution
- How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server
- Can Flink SQL read multiple topics at the same time. How to write in with
- 1008 circular right shift of array elements (20 points)
- 729. My schedule I (set or dynamic open point segment tree)
- 8. Static file
猜你喜欢

How do programmers teach their bosses to do things in one sentence? "I'm off duty first. You have to work harder."

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

coreldraw2022新版本新功能介绍cdr2022
![[detailed steps of FreeRTOS shift value for the first time]](/img/73/a469eb2465bb2c5acaa4d018d3edd3.jpg)
[detailed steps of FreeRTOS shift value for the first time]

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

The implementation of the maize negotiable digital warehouse receipt standard will speed up the asset digitization process of the industry

How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server
![Mlapi series - 04 - network variables and network serialization [network synchronization]](/img/fc/aebbad5295481788de5c1fdb432a77.jpg)
Mlapi series - 04 - network variables and network serialization [network synchronization]

Jd.com 2: how to prevent oversold in the deduction process of commodity inventory?

Cross domain and jsonp details
随机推荐
Word cover underline
满足多元需求:捷码打造3大一站式开发套餐,助力高效开发
Dry goods collection | Vulkan game engine video tutorial
coreldraw2022新版本新功能介绍cdr2022
Mixed development of QML and QWidget (preliminary exploration)
Uva1592 Database
Introduction to hashtable
JVM garbage collector concept
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
[face recognition series] | realize automatic makeup
CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)
Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
Practical development of member management applet 06 introduction to life cycle function and user-defined method
ETCD数据库源码分析——etcdserver bootstrap初始化存储
Deep learning framework installation (tensorflow & pytorch & paddlepaddle)
English Vocabulary - life scene memory method
Can CDC pull the Oracle table in full
word封面下划线
Scala function advanced
C'est un petit résumé de l'étude.