当 Redis 发生高延迟时,到底发生了什么 (2)

> 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节点,需要排查是否是持久化导致的阻 塞。持久化引起主线程阻塞的操作主要有:fork 阻塞、AOF刷盘阻塞。

fork 操作发生在 RDB 和 AOF 重写时,Redis 主线程调用 fork 操作产生共享内存的子进程,由子进程完成对应的持久化工作。如果 fork 操作本身耗时过长,必然会导致主线程的阻塞。

当 Redis 发生高延迟时,到底发生了什么

 

Redis 执行 fork 操作产生的子进程内存占用量表现为与父进程相同,理论上需要一倍的物理内存来完成相应的操作。但是 Linux 具有写时复制技术 (copy-on-write),父子进程会共享相同的物理内存页,当父进程处理写请求时会对需要修改的页复制出一份副本完成写操作,而子进程依然读取 fork 时整个父进程的内存快照。所以,一般来说,fork 不会消耗过多时间。

可以执行 info stats命令获取到 latestforkusec 指标,表示 Redis 最近一次 fork 操作耗时,如果耗时很大,比如超过1秒,则需要做出优化调整。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpdzzp.html