查看哪些redis命令拖慢了redis

Redis提供了一个下面这样的命令统计工具:

127.0.0.1:6379> INFO commandstats

# Commandstats
cmdstat_get:calls=113521268,usec=599075196,usec_per_call=5.28
cmdstat_set:calls=3080568,usec=20100483,usec_per_call=6.52
cmdstat_setnx:calls=130299,usec=769499,usec_per_call=5.91
cmdstat_setex:calls=43550680,usec=323048026,usec_per_call=7.42
cmdstat_del:calls=678167,usec=4675634,usec_per_call=6.89
cmdstat_exists:calls=70131400,usec=274202383,usec_per_call=3.91
cmdstat_incr:calls=1303677,usec=8600579,usec_per_call=6.60
cmdstat_rpush:calls=149308,usec=1251437,usec_per_call=8.38
cmdstat_lpush:calls=604715,usec=20602443,usec_per_call=34.07
cmdstat_lpop:calls=260342,usec=1052702,usec_per_call=4.04
cmdstat_llen:calls=1080344,usec=5086433,usec_per_call=4.71
cmdstat_lrange:calls=1455615,usec=11669398,usec_per_call=8.02
cmdstat_zadd:calls=1134485,usec=151418246,usec_per_call=133.47
cmdstat_zrange:calls=2337130,usec=60310695,usec_per_call=25.81
cmdstat_zrevrange:calls=3759,usec=139180,usec_per_call=37.03
cmdstat_zcard:calls=2012697,usec=9566304,usec_per_call=4.75
cmdstat_hset:calls=168312,usec=999030,usec_per_call=5.94
cmdstat_hget:calls=13762721,usec=48754727,usec_per_call=3.54
cmdstat_hmset:calls=18140305,usec=359516140,usec_per_call=19.82
cmdstat_hincrby:calls=4812055,usec=50845269,usec_per_call=10.57
cmdstat_hdel:calls=267847,usec=1053461,usec_per_call=3.93
cmdstat_hgetall:calls=102520184,usec=1470815749,usec_per_call=14.35
cmdstat_hexists:calls=444240,usec=1875602,usec_per_call=4.22
cmdstat_incrby:calls=252023,usec=1752467,usec_per_call=6.95
cmdstat_select:calls=50892530,usec=175148544,usec_per_call=3.44
cmdstat_expire:calls=22526864,usec=137277313,usec_per_call=6.09
cmdstat_keys:calls=81047,usec=28460925588,usec_per_call=351165.69
cmdstat_ping:calls=22976155,usec=54843018,usec_per_call=2.39
cmdstat_type:calls=53,usec=257,usec_per_call=4.85
cmdstat_sort:calls=1401251,usec=79416000,usec_per_call=56.68
cmdstat_info:calls=73,usec=80129,usec_per_call=1097.66
cmdstat_ttl:calls=1702,usec=7988,usec_per_call=4.69
cmdstat_slowlog:calls=9,usec=453,usec_per_call=50.33

通过这个工具可以查看所有命令统计的快照,比如命令执行了多少次,执行命令所耗费的微秒数(每个命令的总时间和平均时间)

由上面可以看到keys命令非常慢,平均用时351165.69微秒,相当于每条命令平均耗时351毫秒,这个慢命令会阻塞后边的命令。

只需要简单地执行CONFIG RESETSTAT命令就可以重置,这样你就可以得到一个全新的统计结果

 

或者用redis慢日志命令

127.0.0.1:6379> slowlog get 10

posted on 2017-12-30 23:33  dongruiha  阅读(6348)  评论(0编辑  收藏  举报

导航