Redis性能分析工具redis-faina

Author:skatexg

Time:2020/11/20 


redis-faina 是由Instagram 开发并开源的一个Redis 查询分析小工具,redis-faina 是通过Redis的MONITOR命令来实现的,通过对在Redis上执行的query进行监控,统计出一段时间的query特性

1.安装

# git clone https://github.com/facebookarchive/redis-faina.git

 

查看目录结构如下:

# ll

total 20

-rwxr-xr-x 1 root root 1781 Nov 19 15:53 heroku-redistogo-faina.sh

-rw-r--r-- 1 root root 1285 Nov 19 15:53 LICENSE

-rw-r--r-- 1 root root 3267 Nov 19 15:53 README.md

-rwxr-xr-x 1 root root 6568 Nov 19 15:53 redis-faina.py

# ./redis-faina.py -h

usage: redis-faina.py [-h] [--prefix-delimiter PREFIX_DELIMITER]

[--redis-version REDIS_VERSION]

[input]

positional arguments:

input File to parse; will read from stdin otherwise

optional arguments:

-h, --help show this help message and exit

--prefix-delimiter PREFIX_DELIMITER

String to split on for delimiting prefix and rest of

key

--redis-version REDIS_VERSION

Version of the redis server being monitored

 

2.redis-faina的命令

A.通过管道从stdin读取N条命令分析处理

# redis-cli -h xx.xx.xx.xx -p 6379 -a pwd monitor | head -n | redis-faina.py --prefix-delimiter 前缀字符串

B.直接从文件里读取N条命令分析处理

# redis-cli -h xx.xx.xx.xx -p 6379 -a pwd monitor | head -n > /tmp/outfile.txt

# redis-faina.py /tmp/outfile.txt

样例:

# ../redis-4.0.14/src/redis-cli -h xxxxxxxx.redis.rds.aliyuncs.com -p 6379 -a password monitor | head -n 500 | ./redis-faina.py

Warning: Using a password with '-a' option on the command line interface may not be safe.

Overall Stats

========================================

Lines Processed 500                    --总命令数

Commands/Sec 8605.30             --qps

Top Prefixes                                    --前缀最多的数据

========================================

app 221 (44.20%)

oauth2 66 (13.20%)

account 37 (7.40%)

spring 5 (1.00%)

Top Keys                                      -- 使用最多的key

========================================

app:client-subscriptions:06f116682dzPyhnuHw1 21 (4.20%) -- 具体key 请求数量 占比

app:client-detail06f11668RQI1U2dzPyhnuHw1 20 (4.00%)

app:client-subscriptions06f11668N8z3QwRBpI0kf 15 (3.00%)

app:client-detail:06f11668z3QwRBpI0kf 14 (2.80%)

app:client-subscriptions:06f11668r4qVTD6sgIw6 11 (2.20%)

app:client-subscriptions:06f11668snh6vjhjCro5gH 10 (2.00%)

app:client-detail:06f116684qVTD6sgIw6 10 (2.00%)

app:client-subscriptions:06f1166895634f70a8c71917 10 (2.00%)

Top Commands                      -- 使用的最多的命令

========================================

PING 169 (33.80%)

EXISTS 143 (28.60%)

GET 121 (24.20%)

HGET 28 (5.60%)

TTL 14 (2.80%)

TYPE 14 (2.80%)

SETEX 6 (1.20%)

info 1 (0.20%)

Command Time (microsecs)         -- 请求的响应时间分布

========================================

Median 81.25

75% 161.0

90% 262.25

99% 577.0

Heaviest Commands (microsecs)    -- 总体耗时最多的命令

========================================

EXISTS 17417.5

PING 17403.5

GET 15763.0

HGET 3270.5

TTL 1663.5

TYPE 1166.75

SETEX 597.25

info 344.0

Slowest Calls                                            -- 慢请求列表

========================================

1408.0 "GET" "app:client-subscriptions:06f11668r4qVTD6sgIw6"

814.0 "GET" "oauth2:authentication:06f11668e830919bedc"

601.0 "PING"

588.75 "PING"

577.0 "PING"

554.0 "PING"

546.0 "EXISTS" "app:client-detail:06f11668SN8z3QwRBpI0kf"

460.0 "EXISTS" "app:client-detail:06f11668UAm8Mozr"

 

说明:

由于redis MONITOR输出的只有请求开始的时间,所以在一个非常繁忙的redis实例中,根据该请求的开始时间以及下一个请求的开始时间,可以大概估算出一个请求的执行时间。由此可以看出,

redis-faina统计的时间并不是十分精确的,尤其在分析一个非常闲的redis实例时,分析的结果可能差的很多

3.使用场景

1.当redis遇到性能问题时,可以用redis-faina做个在线的快照,可以在线诊断redis问题,相比分析redis全内存数据,更快更方便

2.以后把这个小工具集成到运维平台,用户使用更方便

 

--end---

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值