redis性能分析常见的有以下几个方面:
slowlog-log-slower-than 10000 #查询时间超过10ms的会被记录
slowlog-max-len 128 # 最多记录128个慢查询
另一种是使用config set命令动态修改.例如下面使用config set命令将slowlog-log-slower-than设置为20000微秒.slowlog-max-len设置为1024
config set slowlog-log-slower-than 20000
config set slowlog-max-len 1024
config rewrite
如果需要将Redis将配置持久化到本地配置文件,要执行config rewrite命令,如果slowlog-log-slower-than=0会记录所有命令,slowlog-log-slower-than<0对于任何命令都不会进行记录
127.0.0.1:6379> slowlog get 15
1) 1) (integer) 79674 #slowlog的唯一编号
2) (integer) 1523350838 #此次slowlog事件的发生时间
3) (integer) 2987577 #耗时,以微秒为单位
4) 1) "KEYS"
2) "mid_cache_app_list_*"
127.0.0.1:6379> slowlog len
(integer) 128
slowlog reset
127.0.0.1:6379> scan 0
127.0.0.1:6379> scan 0 count 20 #指定输出的数量
127.0.0.1:6379> scan 0 match *mid_sent* #类似于keys命令按模式匹配
redis 127.0.0.1:6379> sadd setone 1 2 3 foo foobar feelsgood
(integer) 6
redis 127.0.0.1:6379> sscan setone 0 match f*
1) "0"
2) 1) "foo"
2) "feelsgood"
3) "foobar"
redis 127.0.0.1:6379> hmset hash name Tom age 35
OK
redis 127.0.0.1:6379> hscan hash 0
1) "0"
2) 1) "name"
2) "Tom"
3) "age"
4) "35"
echo never > /sys/kernel/mm/transparent_hugepage/enabled
需重启redis才能生效
#查找redis进程id:
redis-cli -p 6319 info|grep process_id
process_id:9213
#查看redis进程的内存使用信息:
cd /proc/9213
#查看该进程使用swap分区的统计信息,以不使用或只有少量的4kB为佳:
cat smaps | grep 'Swap:'
#同时打印出内存映射和swap使用信息:查看那些较大的内存消耗是否引发了大的swap使用
cat smaps | egrep '^(Swap:Size)'
注意:实验功能,请确保redis数据已备份,会对redis服务性能产生影响
Redis software watchdog
#该功能只能动态启用,使用以下命令:
CONFIG SET watchdog-period 500
#注:redis会开始频繁监控自身的延时问题,并把问题输出到日志文件中去。
#关闭watchdog:
CONFIG SET watchdog-period 0
CONFIG SET latency-monitor-threshold 100
默认情况下,阈值设置为0,即禁用redis监控。实际上启用该监控功能,对redis所增加的成本很少.
LATENCY命令的使用方法
127.0.0.1:6379> latency latest
1) 1) "command" #event name
2) (integer) 1480865648 #发生时间
3) (integer) 207 #耗时,毫秒
4) (integer) 239 #从redis启动或上次latency reset以来,这种事件的最大延时记录
127.0.0.1:6379> latency history command
1) 1) (integer) 1480865710
2) (integer) 207
2) 1) (integer) 1480865711
2) (integer) 217
127.0.0.1:6379> latency doctor
Dave, I have observed latency spikes in this Redis instance.
You don't mind talking about it, do you Dave?
1. command: 5 latency spikes (average 300ms, mean deviation 120ms,
period 73.40 sec). Worst all time event 500ms.
I have a few advices for you:
- Your current Slow Log configuration only logs events that are
slower than your configured latency monitor threshold. Please
use 'CONFIG SET slowlog-log-slower-than 1000'.
- Check your Slow Log to understand what are the commands you are
running which are too slow to execute. Please check
http://redis.io/commands/slowlog for more information.