前言
都说 Redis
性能极致,实际到底怎么样呢?我们借助 redis-benchmark
来测试一下。redis-benchmark
是 Redis
自带的测试工具,简直不要太舒服。
性能测试
快速测试
测试命令:redis-benchmark
[root@RLKJ-BT ~]# redis-benchmark ====== PING_INLINE ====== 100000 requests completed in 1.66 seconds 50 parallel clients 3 bytes payload keep alive: 1 98.94% <= 1 milliseconds 99.55% <= 2 milliseconds 99.60% <= 5 milliseconds 99.61% <= 6 milliseconds 99.65% <= 10 milliseconds 99.87% <= 11 milliseconds 99.99% <= 12 milliseconds 100.00% <= 12 milliseconds 60240.96 requests per second ====== PING_BULK ====== 100000 requests completed in 1.53 seconds 50 parallel clients 3 bytes payload keep alive: 1 99.25% <= 1 milliseconds 99.94% <= 2 milliseconds 100.00% <= 2 milliseconds 65146.58 requests per second ====== SET ====== 100000 requests completed in 1.63 seconds 50 parallel clients 3 bytes payload keep alive: 1 99.24% <= 1 milliseconds 99.51% <= 2 milliseconds 99.64% <= 3 milliseconds 99.65% <= 5 milliseconds 99.65% <= 6 milliseconds 99.70% <= 10 milliseconds 99.87% <= 11 milliseconds 100.00% <= 11 milliseconds 61462.82 requests per second ====== GET ====== 100000 requests completed in 1.65 seconds 50 parallel clients 3 bytes payload keep alive: 1 98.37% <= 1 milliseconds 99.40% <= 2 milliseconds 99.55% <= 8 milliseconds 99.60% <= 10 milliseconds 99.72% <= 11 milliseconds 99.98% <= 12 milliseconds 100.00% <= 12 milliseconds 60422.96 requests per second ######## 省略 ########### ====== SADD ====== 100000 requests completed in 1.58 seconds 50 parallel clients 3 bytes payload keep alive: 1 99.15% <= 1 milliseconds 99.86% <= 2 milliseconds 99.90% <= 12 milliseconds 99.95% <= 16 milliseconds 99.99% <= 17 milliseconds 100.00% <= 17 milliseconds 63371.36 requests per second ====== HSET ====== 100000 requests completed in 1.65 seconds 50 parallel clients 3 bytes payload keep alive: 1 98.95% <= 1 milliseconds 99.54% <= 2 milliseconds 99.65% <= 5 milliseconds 99.67% <= 6 milliseconds 99.70% <= 10 milliseconds 99.91% <= 11 milliseconds 100.00% <= 11 milliseconds 60642.81 requests per second ######## 省略 ########### [root@RLKJ-BT ~]# 复制代码
如上,快速测试出的结果非常全,经过删减还有很多,我们比较关注的就是
100%
的时延和QPS
。从上面的结果中我们大致能够得出被测redis
的时延都在十几毫秒,QPS
都在6W
多,性能还是很好的。
精简测试
对于快速测试的结果,我们需要去分析挑选那我们需要的数据,其实 redis-benchmark
已经为我们提供了精简测试模式,我们是同-t 参数指定需要测试的操作类型就可以实现对指定操作的性能进行测试。
例:对 set
和 get
进行 1000000
个请求的性能测试。
[root@RLKJ-BT ~]# redis-benchmark -t set,get -n 1000000 -q SET: 62774.64 requests per second GET: 63195.14 requests per second [root@RLKJ-BT ~]# 复制代码
如上,我们已经拿到了非常精简的数据,我们可以直接将其放到我们的测试报告中。
Pipline 测试
针对业务场景,我们可以通过 pipline
来模拟业务场景,批量提交命令给 redis server
,从而提升性能。
例:我们模拟每个 pipline
执行 10
次命令。
[root@RLKJ-BT ~]# redis-benchmark -t set,get -n 1000000 -q -P 10 SET: 446229.38 requests per second GET: 450450.44 requests per second [root@RLKJ-BT ~]# 复制代码
同样的请求数,你会发现单次执行多条命令的性能数据要比单次执行一条命令的性能数据高出
7
倍多。