当 Redis 发生高延迟时,到底发生了什么?| 原力计划
一条命令执行过程
# 超过 slowlog-log-slower-than 阈值的命令都会被记录到慢查询队列中
# 队列最大长度为 slowlog-max-len
slowlog-log-slower-than 10000
slowlog-max-len 128
> slowlog get
1) 1) (integer) 26
2) (integer) 1450253133
3) (integer) 43097
4) 1) "flushdb"
不合理的命令或者数据结构
> redis-cli -h host -p 12345 --bigkeys
# Scanning the entire keyspace to find biggest keys as well as
# average sizes per key type. You can use -i 0.1 to sleep 0.1 sec
# per 100 SCAN commands (not usually needed).
[00.00%] Biggest hash found so far 'idx:user' with 1 fields
[00.00%] Biggest hash found so far 'idx:product' with 3 fields
[00.00%] Biggest hash found so far 'idx:order' with 14 fields
[02.29%] Biggest hash found so far 'idx:fund' with 16 fields
[02.29%] Biggest hash found so far 'idx:pay' with 69 fields
[04.45%] Biggest set found so far 'indexed_word_set' with 1482 members
[05.93%] Biggest hash found so far 'idx:address' with 159 fields
[11.79%] Biggest hash found so far 'idx:reply' with 196 fields
-------- summary -------
Sampled 1484 keys in the keyspace!
Total key length in bytes is 13488 (avg len 9.09)
Biggest set found 'indexed_word_set' has 1482 members
Biggest hash found 'idx:的' has 196 fields
0 strings with 0 bytes (00.00% of keys, avg size 0.00)
0 lists with 0 items (00.00% of keys, avg size 0.00)
2 sets with 1710 members (00.13% of keys, avg size 855.00)
1482 hashs with 6731 fields (99.87% of keys, avg size 4.54)
0 zsets with 0 members (00.00% of keys, avg size 0.00)
> redis-cli -c -p 7000 info | grep -w latest_fork_usec
latest_fork_usec:315
Asynchronous AOF fsync is taking too long (disk is busy). \
Writing the AOF buffer without waiting for fsync to complete, \
this may slow down Redis.
>info persistence
loading:0
aof_pending_bio_fsync:0
aof_delayed_fsync:0
内存交换
>redis-cli -p 6383 info server | grep process_id # 查询 redis 进程号
>cat /proc/4476/smaps | grep Swap # 查询内存交换大小
Swap: 0 kB
Swap: 4 kB
Swap: 0 kB
Swap: 0 kB
保证机器充足的可用内存;
降低系统使用swap优先级,如echo10>/proc/sys/vm/swappiness;
确保所有Redis实例设置最大可用内存(maxmemory),防止极端情况下 Redis 内存不可控的增长。
热 文 推 荐
