• redis性能压测



    redis性能压测

    redis性能压测工具–redis-benchmark

    如果要对 redis 进行性能压测,可以选择 redis 自带的压测工具 redis-benchmark。

    进入到 /usr/local/software/redis-6.0.9/src 下,使用如下命令开始 redis 性能压测:

    ./redis-benchmark -h 10.0.0.4 -p 6379 -a redis-pass -c 5000 -n 50000 -d 50
    
    • 1

    使用 redis-benchmark -h 命令可以查看 redis-benchmark 相关参数,如下所示:

    Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests>] [-k <boolean>]
    
     -h <hostname>      Server hostname (default 127.0.0.1)
     -p <port>          Server port (default 6379)
     -s <socket>        Server socket (overrides host and port)
     -a <password>      Password for Redis Auth
     --user <username>  Used to send ACL style 'AUTH username pass'. Needs -a.
     -c <clients>       Number of parallel connections (default 50)
     -n <requests>      Total number of requests (default 100000)
     -d <size>          Data size of SET/GET value in bytes (default 3)
     --dbnum <db>       SELECT the specified db number (default 0)
     --threads <num>    Enable multi-thread mode.
     --cluster          Enable cluster mode.
     --enable-tracking  Send CLIENT TRACKING on before starting benchmark.
     -k <boolean>       1=keep alive 0=reconnect (default 1)
     -r <keyspacelen>   Use random keys for SET/GET/INCR, random values for SADD,
                        random members and scores for ZADD.
      Using this option the benchmark will expand the string __rand_int__
      inside an argument with a 12 digits number in the specified range
      from 0 to keyspacelen-1. The substitution changes every time a command
      is executed. Default tests use this to hit random keys in the
      specified range.
     -P <numreq>        Pipeline <numreq> requests. Default 1 (no pipeline).
     -e                 If server replies with errors, show them on stdout.
                        (no more than 1 error per second is displayed)
     -q                 Quiet. Just show query/sec values
     --precision        Number of decimal places to display in latency output (default 0)
     --csv              Output in CSV format
     -l                 Loop. Run the tests forever
     -t <tests>         Only run the comma separated list of tests. The test
                        names are the same as the ones produced as output.
     -I                 Idle mode. Just open N idle connections and wait.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    redis-benchmark 相关参数解释说明

    在这里插入图片描述

    redis-benchmark 压测结果

    redis-benchmark 压测结果如下所示:

    [root@mq1 src]# ./redis-benchmark -h 10.0.0.4 -p 6379 -a redis-pass -c 5000 -n 50000 -d 50
    ====== PING_INLINE ======
      50000 requests completed in 0.74 seconds
      5000 parallel clients
      50 bytes payload
      keep alive: 1
      host configuration "save": 900 1 300 10 60 10000
      host configuration "appendonly": yes
      multi-thread: no
    
    0.00% <= 18 milliseconds
    0.11% <= 19 milliseconds
    0.30% <= 20 milliseconds
    0.78% <= 21 milliseconds
    1.13% <= 22 milliseconds
    1.36% <= 23 milliseconds
    1.71% <= 24 milliseconds
    2.31% <= 25 milliseconds
    3.44% <= 26 milliseconds
    5.26% <= 27 milliseconds
    7.53% <= 28 milliseconds
    9.69% <= 29 milliseconds
    11.74% <= 30 milliseconds
    13.81% <= 31 milliseconds
    15.82% <= 32 milliseconds
    17.74% <= 33 milliseconds
    20.13% <= 34 milliseconds
    22.83% <= 35 milliseconds
    25.27% <= 36 milliseconds
    27.70% <= 37 milliseconds
    30.22% <= 38 milliseconds
    32.75% <= 39 milliseconds
    35.68% <= 40 milliseconds
    39.77% <= 41 milliseconds
    45.01% <= 42 milliseconds
    50.80% <= 43 milliseconds
    55.11% <= 44 milliseconds
    58.44% <= 45 milliseconds
    61.85% <= 46 milliseconds
    64.59% <= 47 milliseconds
    67.36% <= 48 milliseconds
    69.99% <= 49 milliseconds
    72.79% <= 50 milliseconds
    75.65% <= 51 milliseconds
    78.24% <= 52 milliseconds
    80.39% <= 53 milliseconds
    82.34% <= 54 milliseconds
    84.34% <= 55 milliseconds
    86.57% <= 56 milliseconds
    87.80% <= 57 milliseconds
    88.93% <= 58 milliseconds
    89.99% <= 59 milliseconds
    90.70% <= 60 milliseconds
    92.08% <= 61 milliseconds
    92.78% <= 62 milliseconds
    93.35% <= 63 milliseconds
    93.93% <= 64 milliseconds
    94.44% <= 65 milliseconds
    94.70% <= 66 milliseconds
    95.02% <= 67 milliseconds
    95.29% <= 68 milliseconds
    95.53% <= 69 milliseconds
    95.73% <= 70 milliseconds
    96.04% <= 71 milliseconds
    96.34% <= 72 milliseconds
    96.64% <= 73 milliseconds
    97.06% <= 74 milliseconds
    97.44% <= 75 milliseconds
    97.78% <= 76 milliseconds
    97.90% <= 77 milliseconds
    98.17% <= 78 milliseconds
    98.32% <= 79 milliseconds
    98.49% <= 80 milliseconds
    98.71% <= 81 milliseconds
    98.78% <= 82 milliseconds
    98.97% <= 83 milliseconds
    99.12% <= 84 milliseconds
    99.26% <= 85 milliseconds
    99.41% <= 86 milliseconds
    99.57% <= 87 milliseconds
    99.72% <= 88 milliseconds
    99.86% <= 89 milliseconds
    100.00% <= 89 milliseconds
    67659.00 requests per second
    
    ......
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86

    redis-benchmark 压测踩坑

    踩坑一:Can’t create socket: Too many open files

    问题描述:

    在这里插入图片描述

    linux 系统默认 open file 是 1024,程序打开的文件 /socket 连接数量超过系统设定值。可以通过 ulimit -a 命令查看,如下所示:

    在这里插入图片描述

    解决方案:

    1. 通过 ulimit -n 命令临时扩大 open file,如下所示:
    ulimit -n 40960
    
    • 1
    1. 修改 /etc/security/limits.conf 文件永久生效扩大 open file,在文件最后加上以下代码,如下所示:
    * soft nofile 40960
    * hard nofile 40960
    
    • 1
    • 2

    踩坑二:Cannot assign requested address

    问题描述:

    在这里插入图片描述

    这是由于 redis-benchmark 的压力测试时频繁的连服务器,数据量较大的时候,因为每次链接都在很短的时间内结束,致使不少的 TIME_WAIT,以致于用光了可用的端口号,因此新的链接没办法绑定端口,即 “Cannot assign requestedaddress”。

    解决方案:

    执行以下命令:

    # 开启对于TCP时间戳的支持,若该项设置为0,则下面一项设置不起作用
    sysctl -w net.ipv4.tcp_timestamps=1 
    # 表示开启TCP连接中TIME-WAIT sockets的快速回收
    sysctl -w net.ipv4.tcp_tw_recycle=1 
    
    • 1
    • 2
    • 3
    • 4

    然而,执行上述命令后,再次使上述命令进行压测,仍然出现上述问题。因为上述命令设置的请求数和连接数比较大,所以尝试性的减小了其数值,执行之后成功开启 redis-benchmark 的压力测试,如下所示:

    在这里插入图片描述

  • 相关阅读:
    攻防世界----bug
    dc-dc线性降压恒流驱动,40V降压恒流驱动芯片
    Supervisor启动并管理Celery相关进程
    【神印王座】龙皓晨竟然上了头版头条!内容违背,新闻真实性原则
    毕业设计|基于stm32单片机的app视频遥控抽水灭火小车设计
    C专家编程 第10章 再论指针 10.6 使用指针从函数返回一个数组
    最新最全系列之Selenium:传入webdriver驱动的新方法 Service()函数;以前的executable_path报警告,即将弃用
    平面口径天线简谈
    基于单片机的水位检测系统仿真设计
    C 语言 sizeof运算符
  • 原文地址:https://blog.csdn.net/TQ20160412/article/details/127754372