Redis性能报告(单机百万QPS)

本文将对Redis的性能作出定量的分析,一方面是为了加深对Redis服务器的认识,另一方面是为了用reids的性能做一个标准,当自己在单机开发时,自己的服务器是否已经达到最佳性能,来做一个比较。

下面将从运行环境,自测过程,以及官方提供的benchmarks来认清Redis服务器的性能。

压测环境

指标
redis版本 6.0.3
压测工具 redis-benchmark
redis配置 默认配置
服务器 笔记本
CPU Intel Core i7 6核
RAM 16G
磁盘 SSD 512G
环境 Virtual Box 虚拟器 Centos

自测过程

默认配置压测

默认配置

启动Redis不带配置

压测报告

[root@localhost src]# Redis-cli flushall
OK
[root@localhost src]# Redis-benchmark -t set -r 100000 -n 1000000
====== SET ======
  1000000 requests completed in 8.69 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1
  host configuration "save": 3600 1 300 100 60 10000
  host configuration "appendonly": no
  multi-thread: no

0.02% <= 0.1 milliseconds
32.83% <= 0.2 milliseconds
90.55% <= 0.3 milliseconds
97.45% <= 0.4 milliseconds
99.11% <= 0.5 milliseconds
99.52% <= 0.6 milliseconds
99.66% <= 0.7 milliseconds
99.73% <= 0.8 milliseconds
99.77% <= 0.9 milliseconds
99.81% <= 1.0 milliseconds
99.83% <= 1.1 milliseconds
99.86% <= 1.2 milliseconds
99.87% <= 1.3 milliseconds
99.88% <= 1.4 milliseconds
99.89% <= 1.5 milliseconds
99.91% <= 1.6 milliseconds
99.91% <= 1.7 milliseconds
99.92% <= 1.8 milliseconds
99.93% <= 1.9 milliseconds
99.93% <= 2 milliseconds
99.99% <= 3 milliseconds
100.00% <= 6 milliseconds
100.00% <= 6 milliseconds
115074.80 requests per second

perf性能报告

 Performance counter stats for './Redis-server':

          6,694.80 msec task-clock                #    0.319 CPUs utilized      
            23,238      context-switches          #    0.003 M/sec              
                 4      cpu-migrations            #    0.001 K/sec              
             1,954      page-faults               #    0.292 K/sec              
   <not supported>      cycles                                                  
   <not supported>      instructions                                            
   <not supported>      branches                                                
   <not supported>      branch-misses                                           

      20.994908137 seconds time elapsed

       1.927992000 seconds user
       4.902795000 seconds sys

火焰图

perf record -g -F 99 Redis-server ../Redis.conf
perf script -i perf.data >out.perf
~/FlameGraph/stackcollapse-perf.pl out.perf > out.floded
~/FlameGraph/flamegraph.pl out.floded > cp.svg
redis-perf-stat

使用管道优化QPS

结果

[root@localhost src]# Redis-benchmark -n 1000000 -t set,get -P 16 -q
SET: 1136472.75 requests per second
GET: 1492680.50 requests per second

官方benchmarks

官方链接

https://Redis.io/docs/reference/optimization/benchmarks/

对不同CPU的测试报告

下图是对3个不同的CPU进行的基准测试报告。

从下图可以看到,使用英特尔的CPU,跑Redis的性能会更高。

redis-perf-core

客户端连接数的压测报告

下图x轴为客户端连接数,y轴是QPS。

可以看到,随着客户端连接数的增加,性能会不断的下降。即使是使用了epoll。

redis-Connections_chart

影响Redis性能的因素

  • 网络带宽和延迟会直接影响性能。值得考虑使用10 Gbit/s的链路
  • 使用高速缓存大而核数不多的快速CPU。因为核数少,会减少缓存在不同核的同步,使用高速缓存大,可以减少对RAM的直接访问
  • 运行在物理机上,总比运行在虚拟机上要好
  • 使用管道会加大吞吐量
  • 使用更优的内存分配器(tcmalloc jemalloc)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

推荐阅读更多精彩内容