Redis CPU使用率过高问题的排查

Redis CPU占用过高会导致所有使用Redis的客户端性能大幅下降,可能的原因中其中一个是大量的请求,尤其是keys命令请求过多,查询流程:

  1. 使用info和monitor命令(这两个命令也可以登录之后使用,不过有可能造成client的crash)

redis-cli -h 192.168.1.2  -a ‘passwd’ info 

Clients

connected_clients:25
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:1

Memory

used_memory:24022936
used_memory_human:22.91M
used_memory_rss:27422720
used_memory_rss_human:26.15M
used_memory_peak:76894968
used_memory_peak_human:73.33M
total_system_memory:33566736384
total_system_memory_human:31.26G
used_memory_lua:43008
used_memory_lua_human:42.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.14
mem_allocator:jemalloc-4.0.3

Persistence

loading:0
rdb_changes_since_last_save:3502
rdb_bgsave_in_progress:0
rdb_last_save_time:1575614696
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:0
rdb_current_bgsave_time_sec:-1
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok

Stats

total_connections_received:8119852
total_commands_processed:287772910835
instantaneous_ops_per_sec:23686
total_net_input_bytes:8372810113180
total_net_output_bytes:1471697139442
instantaneous_input_kbps:676.85
instantaneous_output_kbps:129.54
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:158935
evicted_keys:0
keyspace_hits:188709502
keyspace_misses:6948953
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:823
migrate_cached_sockets:0

Replication

role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

CPU

used_cpu_sys:3372080.50
used_cpu_user:404838.31
used_cpu_sys_children:851.85
used_cpu_user_children:5934.84

Cluster

cluster_enabled:0

Keyspace

db0:keys=14078,expires=1209,avg_ttl=150542
db6:keys=878,expires=682,avg_ttl=42691293

redis-cli -h 192.168.1.2 -a ‘ passwd ‘ monitor 

info命令会显示当前的状态,monitor会显示当前的客户端的命令请求;

  1. 使用慢查询 

redis-cli -h 192.168.1.xx  -a ‘ passwd ‘ slowlog get (reset替换get清空旧的log)

这个命令会显示出最近一段时间内的耗时较久的查询。

这几个命令综合起来,基本可以找到是哪些命令频繁调用造成系统繁忙。

一般来说,都是大量调用keys命令并使用通配符造成的。

发表评论