Redis性能篇(三)Redis关键系统配置:如何应对Redis变慢GTA

Redis被广泛使用的一个很重要的原因是它的高性能。因此我们必要要重视所有可能影响Redis性能的因素、机制以及应对方案。影响Redis性能的五大方面的潜在因素,分别是:

Redis内部的阻塞式操作
CPU核和NUMA架构的影响
Redis关键系统配置
Redis内存碎片
Redis缓冲区
在前面的2讲中,学习了会导致Redis变慢的潜在阻塞点以及相应的解决方案,即异步线程机制和CPU绑核。除此之外,还有一些因素会导致Redis变慢。

这一讲,介绍如何系统性应对Redis变慢这个问题。从问题认定、系统性排查和应对方案这3个方面来讲解。

判断Redis是否变慢?
最直接的方法,查看Redis的响应延迟。通过绝对值来判断,比如执行时间突然增长到几秒。

但是这个方法在不同配置的机器上的误差比较大。第二个方法是基于当前环境下的Redis基线性能做判断。

基线性能指一个系统在低压力、无干扰下的基本性能。

怎么确定基线性能?从2.8.7版本开始,redis-cli命令提供了-intrinsic-latency选项,可以用来监测和统计测试期间内的最大延迟,这个延迟可以作为Redis的基线性能。其中,测试时长可以用-intrinsic-latency选项的参数来指定。

一般来说,运行时延和基线性能对比,如果运行时延是基线性能的2倍及以上时,就可以认定Redis变慢了。为了避免网络对基线性能的影响,直接在服务器端运行。

如何应对Redis变慢?
影响Redis的关键因素有三个:Redis自身的操作特性、文件系统和操作系统。

Redis自身操作特性的影响
Redis有两个操作会对性能造成较大影响,分别是慢查询命令和过期key操作。

慢查询命令
慢查询命令,就是指在Redis中执行速度慢的命令,这会导致Redis延迟增加。

排查:通过Redis日志、或者是latency monitor工具。

解决方法:

用其他高效命令代替。比如不要使用SMEMBERS命令,而是用SSCAN多次迭代返回;
当需要执行排序、交集、并集操作时,可以在客户端完成,而不要用SORT、SUNION、SINTER这些命令。
还有一个比较容易遗漏的慢查询命令是KEYS命令,它用于返回和输入模式的所有key。因为KEYS命令需要遍历存储的键值对,所以操作延时高。KEYS命令一般不被建议用于生产环境中。

过期key操作
过期key的自动删除机制,它是Redis用来回收内存空间的常用机制,本身会引起Redis操作阻塞,导致性能变慢。

排查:检查业务代码在使用EXPIREAT命令设置key过期时间时,是否使用了相同的UNIX时间戳。因为这会造成大量key在同一时间过期,导致性能变慢。

解决方法:

根据实际业务需求来决定EXPIREAT和EXPIRE的过期时间参数。
如果一批key的确是同时过期,可以在EXPIREAT和EXPIRE的过期时间参数上,加上一个一定大小范围内的随机参数
文件系统的影响
在基础篇讲过,为了保证数据可靠性,Redis会采用AOF日志或者RDB快照。其中,AOF日志提供了三种日志写回策略:no、everysec、always。这三种写回策略依赖文件系统的两个系统调用完成:write和fsync。

write只要把日志记录写到内核缓冲区即可;Redis被广泛使用的一个很重要的原因是它的高性能。因此我们必要要重视所有可能影响Redis性能的因素、机制以及应对方案。影响Redis性能的五大方面的潜在因素,分别是:

Redis内部的阻塞式操作
CPU核和NUMA架构的影响
Redis关键系统配置
Redis内存碎片
Redis缓冲区
在前面的2讲中,学习了会导致Redis变慢的潜在阻塞点以及相应的解决方案,即异步线程机制和CPU绑核。除此之外,还有一些因素会导致Redis变慢。

这一讲,介绍如何系统性应对Redis变慢这个问题。从问题认定、系统性排查和应对方案这3个方面来讲解。

判断Redis是否变慢?
最直接的方法,查看Redis的响应延迟。通过绝对值来判断,比如执行时间突然增长到几秒。
https://github.com/users/aopugfGY/projects/715
https://github.com/users/ofbz122/projects/721
https://github.com/users/zlri87gyr/projects/718
https://github.com/users/iuiz66DY/projects/718
https://github.com/users/fnuh1891/projects/716
https://github.com/users/aopugfGY/projects/716
https://github.com/users/ofbz122/projects/722
https://github.com/users/zlri87gyr/projects/719
https://github.com/users/iuiz66DY/projects/719
https://github.com/users/aopugfGY/projects/717
https://github.com/users/fnuh1891/projects/717
https://github.com/users/aopugfGY/projects/718
https://github.com/users/ofbz122/projects/723
https://github.com/users/zlri87gyr/projects/720
https://github.com/users/iuiz66DY/projects/720
https://github.com/users/fnuh1891/projects/718
https://github.com/users/ofbz122/projects/724
https://github.com/users/aopugfGY/projects/719
https://github.com/users/zlri87gyr/projects/721
https://github.com/users/iuiz66DY/projects/721
https://github.com/users/fnuh1891/projects/719
https://github.com/users/ofbz122/projects/725
https://github.com/users/aopugfGY/projects/720
https://github.com/users/zlri87gyr/projects/722
https://github.com/users/iuiz66DY/projects/722
https://github.com/users/ofbz122/projects/726
https://github.com/users/fnuh1891/projects/720
https://github.com/users/aopugfGY/projects/721
https://github.com/users/zlri87gyr/projects/723
https://github.com/users/iuiz66DY/projects/723
https://github.com/users/fnuh1891/projects/721
https://github.com/users/ofbz122/projects/727
https://github.com/users/zlri87gyr/projects/724
https://github.com/users/aopugfGY/projects/722
https://github.com/users/iuiz66DY/projects/724
https://github.com/users/fnuh1891/projects/722
https://github.com/users/aopugfGY/projects/723
https://github.com/users/ofbz122/projects/728
https://github.com/users/zlri87gyr/projects/725
https://github.com/users/iuiz66DY/projects/725
https://github.com/users/fnuh1891/projects/723
https://github.com/users/aopugfGY/projects/724
https://github.com/users/ofbz122/projects/729
https://github.com/users/zlri87gyr/projects/726
https://github.com/users/iuiz66DY/projects/726
https://github.com/users/fnuh1891/projects/724
https://github.com/users/ofbz122/projects/730
https://github.com/users/aopugfGY/projects/725
https://github.com/users/zlri87gyr/projects/727
https://github.com/users/iuiz66DY/projects/727
https://github.com/users/fnuh1891/projects/725
https://github.com/users/ofbz122/projects/731
https://github.com/users/aopugfGY/projects/726
https://github.com/users/zlri87gyr/projects/728
https://github.com/users/fnuh1891/projects/726
https://github.com/users/aopugfGY/projects/727
https://github.com/users/iuiz66DY/projects/728
https://github.com/users/ofbz122/projects/732
https://github.com/users/zlri87gyr/projects/729
https://github.com/users/fnuh1891/projects/727
https://github.com/users/iuiz66DY/projects/729
https://github.com/users/ofbz122/projects/733
https://github.com/users/aopugfGY/projects/728
https://github.com/users/zlri87gyr/projects/730
https://github.com/users/fnuh1891/projects/728
https://github.com/users/ofbz122/projects/734
https://github.com/users/iuiz66DY/projects/730
https://github.com/users/aopugfGY/projects/729
https://github.com/users/fnuh1891/projects/729
https://github.com/users/ofbz122/projects/735
https://github.com/users/aopugfGY/projects/730
https://github.com/users/iuiz66DY/projects/731
https://github.com/users/fnuh1891/projects/730
https://github.com/users/zlri87gyr/projects/731
https://github.com/users/aopugfGY/projects/731
https://github.com/users/iuiz66DY/projects/732
https://github.com/users/ofbz122/projects/736
https://github.com/users/fnuh1891/projects/731
https://github.com/users/aopugfGY/projects/732
https://github.com/users/zlri87gyr/projects/732
https://github.com/users/ofbz122/projects/737
https://github.com/users/iuiz66DY/projects/733
https://github.com/users/fnuh1891/projects/732
https://github.com/users/zlri87gyr/projects/733
https://github.com/users/aopugfGY/projects/733
https://github.com/users/ofbz122/projects/738
https://github.com/users/iuiz66DY/projects/734
https://github.com/users/fnuh1891/projects/733
https://github.com/users/zlri87gyr/projects/734
https://github.com/users/ofbz122/projects/739
https://github.com/users/aopugfGY/projects/734
https://github.com/users/iuiz66DY/projects/735
https://github.com/users/fnuh1891/projects/734
https://github.com/users/zlri87gyr/projects/735
https://github.com/users/ofbz122/projects/740
https://github.com/users/aopugfGY/projects/735
https://github.com/users/fnuh1891/projects/735
https://github.com/users/iuiz66DY/projects/736
https://github.com/users/zlri87gyr/projects/736
https://github.com/users/ofbz122/projects/741
https://github.com/users/fnuh1891/projects/736
https://github.com/users/aopugfGY/projects/736
https://github.com/users/iuiz66DY/projects/737
https://github.com/users/zlri87gyr/projects/737
https://github.com/users/ofbz122/projects/742
https://github.com/users/aopugfGY/projects/737
https://github.com/users/fnuh1891/projects/737
https://github.com/users/iuiz66DY/projects/738
https://github.com/users/zlri87gyr/projects/738
https://github.com/users/ofbz122/projects/743
https://github.com/users/aopugfGY/projects/738
https://github.com/users/fnuh1891/projects/738
https://github.com/users/iuiz66DY/projects/739
https://github.com/users/zlri87gyr/projects/739
https://github.com/users/ofbz122/projects/744
https://github.com/users/aopugfGY/projects/739
https://github.com/users/fnuh1891/projects/739
https://github.com/users/iuiz66DY/projects/740
https://github.com/users/zlri87gyr/projects/740
https://github.com/users/ofbz122/projects/745
https://github.com/users/aopugfGY/projects/740
https://github.com/users/fnuh1891/projects/740
https://github.com/users/zlri87gyr/projects/741
https://github.com/users/iuiz66DY/projects/741
https://github.com/users/ofbz122/projects/746
https://github.com/users/aopugfGY/projects/741
https://github.com/users/zlri87gyr/projects/742
https://github.com/users/iuiz66DY/projects/742
https://github.com/users/fnuh1891/projects/741
https://github.com/users/ofbz122/projects/747
https://github.com/users/aopugfGY/projects/742
https://github.com/users/iuiz66DY/projects/743
https://github.com/users/zlri87gyr/projects/743
https://github.com/users/fnuh1891/projects/742
https://github.com/users/aopugfGY/projects/743
https://github.com/users/ofbz122/projects/748
https://github.com/users/iuiz66DY/projects/744
https://github.com/users/zlri87gyr/projects/744
https://github.com/users/fnuh1891/projects/743
https://github.com/users/iuiz66DY/projects/745
https://github.com/users/aopugfGY/projects/744
https://github.com/users/ofbz122/projects/749
https://github.com/users/zlri87gyr/projects/745
https://github.com/users/fnuh1891/projects/744
https://github.com/users/iuiz66DY/projects/746
https://github.com/users/aopugfGY/projects/745
https://github.com/users/ofbz122/projects/750
https://github.com/users/zlri87gyr/projects/746
https://github.com/users/fnuh1891/projects/745
https://github.com/users/ofbz122/projects/751
https://github.com/users/iuiz66DY/projects/747
https://github.com/users/aopugfGY/projects/746
https://github.com/users/fnuh1891/projects/746
https://github.com/users/iuiz66DY/projects/748
https://github.com/users/ofbz122/projects/752
https://github.com/users/aopugfGY/projects/747
https://github.com/users/zlri87gyr/projects/747
https://github.com/users/fnuh1891/projects/747
https://github.com/users/iuiz66DY/projects/749
https://github.com/users/ofbz122/projects/753
https://github.com/users/aopugfGY/projects/748
https://github.com/users/zlri87gyr/projects/748
https://github.com/users/fnuh1891/projects/748
https://github.com/users/ofbz122/projects/754
https://github.com/users/iuiz66DY/projects/750
https://github.com/users/aopugfGY/projects/749
https://github.com/users/zlri87gyr/projects/749
https://github.com/users/fnuh1891/projects/749
https://github.com/users/ofbz122/projects/755
https://github.com/users/fnuh1891/projects/750
https://github.com/users/iuiz66DY/projects/751
https://github.com/users/zlri87gyr/projects/750
https://github.com/users/aopugfGY/projects/750
https://github.com/users/ofbz122/projects/756
https://github.com/users/aopugfGY/projects/751
https://github.com/users/fnuh1891/projects/751
https://github.com/users/iuiz66DY/projects/752
https://github.com/users/zlri87gyr/projects/751
https://github.com/users/ofbz122/projects/757
https://github.com/users/aopugfGY/projects/752
https://github.com/users/fnuh1891/projects/752
https://github.com/users/iuiz66DY/projects/753
https://github.com/users/zlri87gyr/projects/752
https://github.com/users/ofbz122/projects/758
https://github.com/users/aopugfGY/projects/753
https://github.com/users/fnuh1891/projects/753
https://github.com/users/iuiz66DY/projects/754
https://github.com/users/zlri87gyr/projects/753
https://github.com/users/ofbz122/projects/759
https://github.com/users/aopugfGY/projects/754
https://github.com/users/fnuh1891/projects/754
https://github.com/users/iuiz66DY/projects/755
https://github.com/users/zlri87gyr/projects/754
https://github.com/users/ofbz122/projects/760
https://github.com/users/fnuh1891/projects/755
https://github.com/users/aopugfGY/projects/755
https://github.com/users/iuiz66DY/projects/756
https://github.com/users/ofbz122/projects/761
https://github.com/users/zlri87gyr/projects/755
https://github.com/users/fnuh1891/projects/756
https://github.com/users/aopugfGY/projects/756
https://github.com/users/iuiz66DY/projects/757
https://github.com/users/ofbz122/projects/762
https://github.com/users/aopugfGY/projects/757
https://github.com/users/zlri87gyr/projects/756
https://github.com/users/fnuh1891/projects/757
https://github.com/users/iuiz66DY/projects/758
https://github.com/users/aopugfGY/projects/758
https://github.com/users/ofbz122/projects/763
https://github.com/users/zlri87gyr/projects/757
https://github.com/users/fnuh1891/projects/758
https://github.com/users/iuiz66DY/projects/759
https://github.com/users/ofbz122/projects/764
https://github.com/users/aopugfGY/projects/759
https://github.com/users/zlri87gyr/projects/758
https://github.com/users/iuiz66DY/projects/760
https://github.com/users/fnuh1891/projects/759
https://github.com/users/ofbz122/projects/765
https://github.com/users/zlri87gyr/projects/759
https://github.com/users/aopugfGY/projects/760
https://github.com/users/fnuh1891/projects/760
https://github.com/users/ofbz122/projects/766
https://github.com/users/iuiz66DY/projects/761
https://github.com/users/zlri87gyr/projects/760
https://github.com/users/aopugfGY/projects/761
https://github.com/users/fnuh1891/projects/761
https://github.com/users/iuiz66DY/projects/762
https://github.com/users/ofbz122/projects/767
https://github.com/users/zlri87gyr/projects/761
https://github.com/users/iuiz66DY/projects/763
https://github.com/users/fnuh1891/projects/762
https://github.com/users/aopugfGY/projects/762
https://github.com/users/ofbz122/projects/768
https://github.com/users/zlri87gyr/projects/762
https://github.com/users/aopugfGY/projects/763
https://github.com/users/fnuh1891/projects/763
https://github.com/users/iuiz66DY/projects/764
https://github.com/users/ofbz122/projects/769
https://github.com/users/zlri87gyr/projects/763
https://github.com/users/fnuh1891/projects/764
https://github.com/users/iuiz66DY/projects/765
https://github.com/users/aopugfGY/projects/764
https://github.com/users/ofbz122/projects/770
https://github.com/users/zlri87gyr/projects/764
https://github.com/users/aopugfGY/projects/765
https://github.com/users/zlri87gyr/projects/765
https://github.com/users/fnuh1891/projects/765
https://github.com/users/ofbz122/projects/771
https://github.com/users/iuiz66DY/projects/766
https://github.com/users/aopugfGY/projects/766
https://github.com/users/zlri87gyr/projects/766
https://github.com/users/iuiz66DY/projects/767
https://github.com/users/ofbz122/projects/772
https://github.com/users/fnuh1891/projects/766
https://github.com/users/aopugfGY/projects/767
https://github.com/users/iuiz66DY/projects/768
https://github.com/users/zlri87gyr/projects/767
https://github.com/users/ofbz122/projects/773
https://github.com/users/fnuh1891/projects/767
https://github.com/users/iuiz66DY/projects/769
https://github.com/users/aopugfGY/projects/768
https://github.com/users/ofbz122/projects/774
https://github.com/users/zlri87gyr/projects/768
https://github.com/users/fnuh1891/projects/768
https://github.com/users/iuiz66DY/projects/770
https://github.com/users/aopugfGY/projects/769
https://github.com/users/zlri87gyr/projects/769
https://github.com/users/ofbz122/projects/775
https://github.com/users/fnuh1891/projects/769
https://github.com/users/iuiz66DY/projects/771
https://github.com/users/fnuh1891/projects/770
https://github.com/users/aopugfGY/projects/770
https://github.com/users/zlri87gyr/projects/770
https://github.com/users/ofbz122/projects/776
https://github.com/users/iuiz66DY/projects/772
https://github.com/users/aopugfGY/projects/771
https://github.com/users/zlri87gyr/projects/771
https://github.com/users/fnuh1891/projects/771
https://github.com/users/ofbz122/projects/777
https://github.com/users/iuiz66DY/projects/773
https://github.com/users/zlri87gyr/projects/772
https://github.com/users/fnuh1891/projects/772
https://github.com/users/aopugfGY/projects/772
https://github.com/users/ofbz122/projects/778
https://github.com/users/iuiz66DY/projects/774
https://github.com/users/zlri87gyr/projects/773
https://github.com/users/fnuh1891/projects/773
https://github.com/users/aopugfGY/projects/773
https://github.com/users/ofbz122/projects/779
https://github.com/users/iuiz66DY/projects/775
https://github.com/users/zlri87gyr/projects/774
https://github.com/users/aopugfGY/projects/774
https://github.com/users/fnuh1891/projects/774
https://github.com/users/ofbz122/projects/780
https://github.com/users/iuiz66DY/projects/776
https://github.com/users/zlri87gyr/projects/775
https://github.com/users/aopugfGY/projects/775
https://github.com/users/fnuh1891/projects/775
https://github.com/users/ofbz122/projects/781
https://github.com/users/iuiz66DY/projects/777
https://github.com/users/zlri87gyr/projects/776
https://github.com/users/aopugfGY/projects/776
https://github.com/users/fnuh1891/projects/776
https://github.com/users/ofbz122/projects/782
https://github.com/users/iuiz66DY/projects/778
https://github.com/users/zlri87gyr/projects/777
https://github.com/users/aopugfGY/projects/777
https://github.com/users/fnuh1891/projects/777
https://github.com/users/ofbz122/projects/783
https://github.com/users/iuiz66DY/projects/779
https://github.com/users/fnuh1891/projects/778
https://github.com/users/zlri87gyr/projects/778
https://github.com/users/aopugfGY/projects/778
https://github.com/users/ofbz122/projects/784
https://github.com/users/iuiz66DY/projects/780
https://github.com/users/fnuh1891/projects/779
https://github.com/users/zlri87gyr/projects/779
https://github.com/users/aopugfGY/projects/779
https://github.com/users/ofbz122/projects/785
https://github.com/users/fnuh1891/projects/780
https://github.com/users/zlri87gyr/projects/780
https://github.com/users/iuiz66DY/projects/781
https://github.com/users/aopugfGY/projects/780
https://github.com/users/ofbz122/projects/786
https://github.com/users/fnuh1891/projects/781
https://github.com/users/iuiz66DY/projects/782
https://github.com/users/zlri87gyr/projects/781
https://github.com/users/aopugfGY/projects/781
https://github.com/users/ofbz122/projects/787
https://github.com/users/iuiz66DY/projects/783
https://github.com/users/fnuh1891/projects/782
https://github.com/users/aopugfGY/projects/782
https://github.com/users/zlri87gyr/projects/782
https://github.com/users/ofbz122/projects/788
https://github.com/users/iuiz66DY/projects/784
https://github.com/users/fnuh1891/projects/783
https://github.com/users/aopugfGY/projects/783
https://github.com/users/zlri87gyr/projects/783
https://github.com/users/iuiz66DY/projects/785
https://github.com/users/ofbz122/projects/789
https://github.com/users/fnuh1891/projects/784
https://github.com/users/aopugfGY/projects/784
https://github.com/users/zlri87gyr/projects/784
https://github.com/users/iuiz66DY/projects/786
https://github.com/users/ofbz122/projects/790
https://github.com/users/fnuh1891/projects/785
https://github.com/users/aopugfGY/projects/785
https://github.com/users/zlri87gyr/projects/785
https://github.com/users/ofbz122/projects/791
https://github.com/users/iuiz66DY/projects/787
https://github.com/users/fnuh1891/projects/786
https://github.com/users/aopugfGY/projects/786
https://github.com/users/zlri87gyr/projects/786
https://github.com/users/fnuh1891/projects/787
https://github.com/users/ofbz122/projects/792
https://github.com/users/iuiz66DY/projects/788
https://github.com/users/aopugfGY/projects/787
https://github.com/users/zlri87gyr/projects/787
https://github.com/users/iuiz66DY/projects/789
https://github.com/users/fnuh1891/projects/788
https://github.com/users/ofbz122/projects/793
https://github.com/users/aopugfGY/projects/788
https://github.com/users/zlri87gyr/projects/788
https://github.com/users/fnuh1891/projects/789
https://github.com/users/iuiz66DY/projects/790
https://github.com/users/ofbz122/projects/794
https://github.com/users/aopugfGY/projects/789
https://github.com/users/zlri87gyr/projects/789
https://github.com/users/iuiz66DY/projects/791
https://github.com/users/fnuh1891/projects/790
https://github.com/users/aopugfGY/projects/790
https://github.com/users/ofbz122/projects/795
https://github.com/users/zlri87gyr/projects/790
https://github.com/users/iuiz66DY/projects/792
https://github.com/users/fnuh1891/projects/791
https://github.com/users/aopugfGY/projects/791
https://github.com/users/zlri87gyr/projects/791
https://github.com/users/ofbz122/projects/796
https://github.com/users/iuiz66DY/projects/793
https://github.com/users/fnuh1891/projects/792
https://github.com/users/aopugfGY/projects/792
https://github.com/users/zlri87gyr/projects/792
https://github.com/users/ofbz122/projects/797
https://github.com/users/fnuh1891/projects/793
https://github.com/users/aopugfGY/projects/793
https://github.com/users/iuiz66DY/projects/794
https://github.com/users/zlri87gyr/projects/793
https://github.com/users/ofbz122/projects/798
https://github.com/users/iuiz66DY/projects/795
https://github.com/users/fnuh1891/projects/794
https://github.com/users/aopugfGY/projects/794
https://github.com/users/ofbz122/projects/799
https://github.com/users/zlri87gyr/projects/794
https://github.com/users/iuiz66DY/projects/796
https://github.com/users/fnuh1891/projects/795
https://github.com/users/aopugfGY/projects/795
https://github.com/users/ofbz122/projects/800
https://github.com/users/zlri87gyr/projects/795
https://github.com/users/iuiz66DY/projects/797
https://github.com/users/fnuh1891/projects/796
https://github.com/users/aopugfGY/projects/796
https://github.com/users/zlri87gyr/projects/796
https://github.com/users/ofbz122/projects/801
https://github.com/users/fnuh1891/projects/797
https://github.com/users/zlri87gyr/projects/797
https://github.com/users/fnuh1891/projects/798
https://github.com/users/iuiz66DY/projects/798
https://github.com/users/zlri87gyr/projects/798
https://github.com/users/fnuh1891/projects/799
https://github.com/users/ofbz122/projects/802
https://github.com/users/iuiz66DY/projects/799
https://github.com/users/aopugfGY/projects/797
https://github.com/users/zlri87gyr/projects/799
https://github.com/users/ofbz122/projects/803
https://github.com/users/aopugfGY/projects/798
https://github.com/users/iuiz66DY/projects/800
https://github.com/users/fnuh1891/projects/800
https://github.com/users/zlri87gyr/projects/800
https://github.com/users/ofbz122/projects/804
https://github.com/users/fnuh1891/projects/801
https://github.com/users/iuiz66DY/projects/801
https://github.com/users/aopugfGY/projects/799
https://github.com/users/zlri87gyr/projects/801
https://github.com/users/fnuh1891/projects/802
https://github.com/users/ofbz122/projects/805
https://github.com/users/iuiz66DY/projects/802
https://github.com/users/aopugfGY/projects/800
https://github.com/users/zlri87gyr/projects/802
https://github.com/users/fnuh1891/projects/803
https://github.com/users/ofbz122/projects/806
https://github.com/users/aopugfGY/projects/801
https://github.com/users/iuiz66DY/projects/803
https://github.com/users/zlri87gyr/projects/803
https://github.com/users/fnuh1891/projects/804
https://github.com/users/ofbz122/projects/807
https://github.com/users/zlri87gyr/projects/804
https://github.com/users/iuiz66DY/projects/804
https://github.com/users/aopugfGY/projects/802
https://github.com/users/fnuh1891/projects/805
https://github.com/users/ofbz122/projects/808
https://github.com/users/iuiz66DY/projects/805
https://github.com/users/zlri87gyr/projects/805
https://github.com/users/ofbz122/projects/809
https://github.com/users/zlri87gyr/projects/806
https://github.com/users/ofbz122/projects/810
https://github.com/users/zlri87gyr/projects/807
https://github.com/users/iuiz66DY/projects/806
https://github.com/users/aopugfGY/projects/803
https://github.com/users/fnuh1891/projects/806
https://github.com/users/iuiz66DY/projects/807
https://github.com/users/aopugfGY/projects/804
https://github.com/users/zlri87gyr/projects/808
https://github.com/users/ofbz122/projects/811
https://github.com/users/fnuh1891/projects/807
https://github.com/users/iuiz66DY/projects/808
https://github.com/users/aopugfGY/projects/805
https://github.com/users/zlri87gyr/projects/809
https://github.com/users/ofbz122/projects/812
https://github.com/users/iuiz66DY/projects/809
https://github.com/users/fnuh1891/projects/808
https://github.com/users/aopugfGY/projects/806
https://github.com/users/zlri87gyr/projects/810
https://github.com/users/ofbz122/projects/813
https://github.com/users/iuiz66DY/projects/810
https://github.com/users/fnuh1891/projects/809
https://github.com/users/aopugfGY/projects/807
https://github.com/users/zlri87gyr/projects/811
https://github.com/users/fnuh1891/projects/810
https://github.com/users/iuiz66DY/projects/811
https://github.com/users/ofbz122/projects/814
https://github.com/users/aopugfGY/projects/808
https://github.com/users/iuiz66DY/projects/812
https://github.com/users/fnuh1891/projects/811
https://github.com/users/zlri87gyr/projects/812
https://github.com/users/ofbz122/projects/815
https://github.com/users/aopugfGY/projects/809
https://github.com/users/iuiz66DY/projects/813
https://github.com/users/fnuh1891/projects/812
https://github.com/users/zlri87gyr/projects/813
https://github.com/users/ofbz122/projects/816
https://github.com/users/iuiz66DY/projects/814
https://github.com/users/aopugfGY/projects/810
https://github.com/users/zlri87gyr/projects/814
https://github.com/users/fnuh1891/projects/813
https://github.com/users/ofbz122/projects/817
https://github.com/users/iuiz66DY/projects/815
https://github.com/users/aopugfGY/projects/811
https://github.com/users/zlri87gyr/projects/815
https://github.com/users/fnuh1891/projects/814
https://github.com/users/iuiz66DY/projects/816
https://github.com/users/aopugfGY/projects/812
https://github.com/users/zlri87gyr/projects/816
https://github.com/users/fnuh1891/projects/815
https://github.com/users/iuiz66DY/projects/817
https://github.com/users/ofbz122/projects/818
https://github.com/users/zlri87gyr/projects/817
https://github.com/users/aopugfGY/projects/813
但是这个方法在不同配置的机器上的误差比较大。第二个方法是基于当前环境下的Redis基线性能做判断。

基线性能指一个系统在低压力、无干扰下的基本性能。

怎么确定基线性能?从2.8.7版本开始,redis-cli命令提供了-intrinsic-latency选项,可以用来监测和统计测试期间内的最大延迟,这个延迟可以作为Redis的基线性能。其中,测试时长可以用-intrinsic-latency选项的参数来指定。

一般来说,运行时延和基线性能对比,如果运行时延是基线性能的2倍及以上时,就可以认定Redis变慢了。为了避免网络对基线性能的影响,直接在服务器端运行。

如何应对Redis变慢?
影响Redis的关键因素有三个:Redis自身的操作特性、文件系统和操作系统。

Redis自身操作特性的影响
Redis有两个操作会对性能造成较大影响,分别是慢查询命令和过期key操作。
把你的脸迎向阳光,那就不会有阴影
.经验是由痛苦中粹取出来的
用最少的悔恨面对过去
用最少的浪费面对现在
用最多的梦面对未来
快乐不是因为拥有的多而是计较的少
你的选择是做或不做,但不做就永远不会有机会
如你想要拥有完美无暇的友谊,可能一辈子找不到朋友
不如意的时候不要尽往悲伤里钻,想想有笑声的日子吧
把自己当傻瓜,不懂就问,你会学的更多
要纠正别人之前,先反省自己有没有犯错

不要等待机会,而要创造机会。
态度决定命运。
量变引起质变,知识重在积累。
有怎样的开始,就有怎样的结束。
行动是通往知识的唯一道路。
当你能梦的时候就不要放弃梦。
快乐要懂得分享,才能加倍地快乐。
良好的习惯永远是一个人成功的法宝。
总结,就是为了在高考中不留下任何遗憾。
良好的生活习惯对人的一生都至关重要。
一个今天胜过两个明天。
把你的脸迎向阳光,那就不会有阴影。
经验是由痛苦中萃取出来的。
闲事闲话闲思是学习的大敌。
不要被失败吓到,不要被胜利冲昏头脑。
一个成功者只知抱定理想,向前行进。
乐观地对待失败,成功就会向你招手。
你不能左右天气,但你能转变你的心情。
始终保持积极向上的精神状态,就会创造出惊人的成绩。
积极的人在每一次失败中都看到机会。
含累播种的人一定能含笑收获。
一个人最大的破产是绝望,最大的资产是希望。
做对的事情比把事情做对重要。
平时和考试一样,考试方和平时一样。
每天告诉自己一次:我真的很不错。
生活中若没有明天,就像生活中没有阳光一样。
发光并非太阳的专利,你也可以发光。
人只要不失去方向,就不会失去自己。
嫉妒别人,仇视异己,就等于把生命交给别人。
平生不做皱眉事,世上应无切齿人。
嫉妒别人,仇视异己,就等于把生命交给别人。
平生不做皱眉事,世上应无切齿人。
智者顺时而谋,愚者逆时而动。
心量狭小,则多烦恼,心量广大,智慧丰饶。
人若勇敢就是自己最好的朋友
不可能』只存在于蠢人的字典里
抱最大的希望,为最大的努力,做最坏的打算
家!甜蜜的家!天下最美好的莫过于家
慢查询命令
慢查询命令,就是指在Redis中执行速度慢的命令,这会导致Redis延迟增加。

排查:通过Redis日志、或者是latency monitor工具。

解决方法:

用其他高效命令代替。比如不要使用SMEMBERS命令,而是用SSCAN多次迭代返回;
当需要执行排序、交集、并集操作时,可以在客户端完成,而不要用SORT、SUNION、SINTER这些命令。
还有一个比较容易遗漏的慢查询命令是KEYS命令,它用于返回和输入模式的所有key。因为KEYS命令需要遍历存储的键值对,所以操作延时高。KEYS命令一般不被建议用于生产环境中。

过期key操作
过期key的自动删除机制,它是Redis用来回收内存空间的常用机制,本身会引起Redis操作阻塞,导致性能变慢。

排查:检查业务代码在使用EXPIREAT命令设置key过期时间时,是否使用了相同的UNIX时间戳。因为这会造成大量key在同一时间过期,导致性能变慢。

解决方法:

根据实际业务需求来决定EXPIREAT和EXPIRE的过期时间参数。
如果一批key的确是同时过期,可以在EXPIREAT和EXPIRE的过期时间参数上,加上一个一定大小范围内的随机参数
文件系统的影响
在基础篇讲过,为了保证数据可靠性,Redis会采用AOF日志或者RDB快照。其中,AOF日志提供了三种日志写回策略:no、everysec、always。这三种写回策略依赖文件系统的两个系统调用完成:write和fsync。

write只要把日志记录写到内核缓冲区即可;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值