• Twemproxy和Redis性能压力测试


    性能测试

    Redis自带了一个叫 redis-benchmark的工具来模拟N个客户端同时发出M个请求,(类似于Apache ab程序),你可以使用redis-benchmark -h来查看基准参数。

    Usage: redis-benchmark [-h ] [-p ] [-c ] [-n  [-k ]
    
    -h       #指定服务器名称(default 127.0.0.1);
    -p           #指定服务器端口(default 6379);
    -s         #指定服务器Socket(overrides host and port);
    -a       #指定Redis密码;
    -c        #指定并行客户端数量 (default 50);
    -n       #指定总的请求数量(default 100000);
    -d           #指定SET/GET一次数据大小 (default 2 Bytes);
    -dbnum         #选择指定的数据库(default 0);
    -k        #保持一个连接,一台服务器来处理这些请求 (default 1);
    -r    #设置随机Key;
    -P         #Pipeline  requests. Default 1 (no pipeline).
    -q                 #显示每秒钟能处理多少请求数结果;
    --csv              #输出为CSV格式;
    -l                 #Loop. Run the tests forever.
    -I                 #Idle mode. Just open N idle connections and wait.
    

    这里用redis自带的benchmark工具测试,由于twemproxy不支持ping命令,所以对于twemproxy只测试set, get, incr, lpush, lpop, sadd, spop, lpush, lrange_100, lrange_300, lrange_500, lrange_600,mset命令。

    Redis单实例简单测试

    1)客户端分别为1/1000/5000,总请求数为100000,Key大小为1k,针对set/get命令测试QPS和完成时间(服务器:CPU 64核,内存 64G)

    # redis-benchmark -h 0.0.0.0 -p 6500 -c 1 -t set,get -d 1000
    ====== SET ======
     100000 requests completed in 2.65 seconds    #完成时间
     1 parallel clients
     1000 bytes payload
     keep alive: 1
    
    100.00% < = 0 milliseconds
    37764.35 requests per second                  #每秒请求数
    
    ====== GET ======
     100000 requests completed in 1.70 seconds
     1 parallel clients
     1000 bytes payload
     keep alive: 1
    
    100.00% <= 0 milliseconds
    58962.27 requests per second
    
    # redis-benchmark -h 0.0.0.0 -p 6500 -c 1000 -t set,get -d 1000
    ====== SET ======
     100000 requests completed in 0.75 seconds
     1000 parallel clients
     1000 bytes payload
     keep alive: 1
    
    0.00% < = 4 milliseconds
    ....................
    100.00% <= 14 milliseconds
    132450.33 requests per second
    
    ====== GET ======
     100000 requests completed in 0.78 seconds
     1000 parallel clients
     1000 bytes payload
     keep alive: 1
    
    0.00% <= 3 milliseconds
    ..................
    100.00% <= 8 milliseconds
    128205.13 requests per second
    
    # redis-benchmark -h 0.0.0.0 -p 6500 -c 5000 -t set,get -d 1000
    ====== SET ======
      100000 requests completed in 1.18 seconds
      5000 parallel clients
      1000 bytes payload
      keep alive: 1
    
    0.00% < = 28 milliseconds
    ..........................
    100.00% <= 105 milliseconds
    84817.64 requests per second
    
    ====== GET ======
      100000 requests completed in 1.24 seconds
      5000 parallel clients
      1000 bytes payload
      keep alive: 1
    
    0.00% <= 35 milliseconds
    .......................
    100.00% <= 55 milliseconds
    80580.17 requests per second
    

    下面提供一个CPU 8核,内存8G的压测结果。

    root@shd-ops-mng1:~ # redis-benchmark -h 0.0.0.0 -p 6380 -c 1 -t set,get -d 1000
    ====== SET ======
      100000 requests completed in 6.50 seconds
      1 parallel clients
      1000 bytes payload
      keep alive: 1
    
    98.95% < = 1 milliseconds
    ...................
    100.00% <= 6 milliseconds
    15379.88 requests per second
    
    ====== GET ======
      100000 requests completed in 6.68 seconds
      1 parallel clients
      1000 bytes payload
      keep alive: 1
    
    98.91% <= 1 milliseconds
    ..................
    100.00% <= 4 milliseconds
    14965.58 requests per second
    
    # redis-benchmark -h 0.0.0.0 -p 6380 -c 1000 -t set,get -d 1000
    ====== SET ======
      100000 requests completed in 0.96 seconds
      1000 parallel clients
      1000 bytes payload
      keep alive: 1
    
    0.00% < = 4 milliseconds
    ....................
    103734.44 requests per second
    
    ====== GET ======
      100000 requests completed in 1.00 seconds
      1000 parallel clients
      1000 bytes payload
      keep alive: 1
    
    0.00% <= 3 milliseconds
    ...................
    100.00% <= 15 milliseconds
    100300.91 requests per second
    

    默认情况下面,基准测试使用单一的key。在一个基于内存的数据库里, 单一key测试和真实情况下面不会有巨大变化。当然,使用一个大的key范围空间, 可以模拟现实情况下面的缓存不命中情况。

    这时候我们可以使用-r命令。比如,假设我们想设置10万随机key连续SET 100万次,连接客户端分别为1/5/1000,我们可以使用下列的命令:

    # redis-benchmark -h 0.0.0.0 -p 6500 -c 1 -r 100000 -q 1000000 -t set -d 1000 -q
    1000000 -t set -d 1000 -q: 63051.70 requests per second
    
    # redis-benchmark -h 0.0.0.0 -p 6500 -c 1000 -r 100000 -q 1000000 -t set -d 1000 -q
    1000000 -t set -d 1000 -q: 94966.77 requests per second
    
    # redis-benchmark -h 0.0.0.0 -p 6500 -c 5000 -r 100000 -q 1000000 -t set -d 1000 -q
    1000000 -t set -d 1000 -q: 83542.19 requests per second
    
    测试twemproxy
    # redis-benchmark -h 0.0.0.0 -p 36379 -c 1 -t set,get -d 1000 
    ====== SET ======
      10000 requests completed in 1.08 seconds
      1 parallel clients
      1000 bytes payload
      keep alive: 1
    
    100.00% < = 0 milliseconds
    9267.84 requests per second
    
    ====== GET ======
      10000 requests completed in 1.08 seconds
      1 parallel clients
      1000 bytes payload
      keep alive: 1
    
    100.00% <= 0 milliseconds
    9293.68 requests per second
    
    # redis-benchmark -h 0.0.0.0 -p 36379 -c 1000 -t set,get -d 1000 
    ====== SET ======
      10000 requests completed in 0.18 seconds
      1000 parallel clients
      1000 bytes payload
      keep alive: 1
    
    0.01% < = 3 milliseconds
    ................
    100.00% <= 20 milliseconds
    55555.55 requests per second
    
    ====== GET ======
      10000 requests completed in 0.21 seconds
      1000 parallel clients
      1000 bytes payload
      keep alive: 1
    
    0.01% <= 5 milliseconds
    ..............
    100.00% <= 23 milliseconds
    47393.37 requests per second
    
    # redis-benchmark -h 0.0.0.0 -p 36379 -c 5000 -t set,get -d 1000 
    ====== SET ======
      10000 requests completed in 0.28 seconds
      5000 parallel clients
      1000 bytes payload
      keep alive: 1
    
    0.01% < = 28 milliseconds
    .......................
    100.00% <= 87 milliseconds
    35587.19 requests per second
    
    ====== GET ======
      10000 requests completed in 0.29 seconds
      5000 parallel clients
      1000 bytes payload
      keep alive: 1
    
    0.01% <= 33 milliseconds
    ....................
    100.00% <= 85 milliseconds
    34364.26 requests per second
  • 相关阅读:
    Codeforces Round #454 Div. 2 A B C (暂时)
    Codeforces Round #453 Div. 2 A B C D (暂时)
    EOJ Monthly 2017.12 A B C D
    C++调用Matlab引擎 图像读写与处理 (知识+代码篇)
    Codeforces Round #449 Div. 2 A B C (暂时)
    AtCoder Regular Contest 077 E
    hdu 6218 Bridge 线段树 set
    hdu 2243 考研路茫茫——单词情结 AC自动机 矩阵幂次求和
    php配置php-fpm启动参数及配置详解
    PHP连接MySQL数据库的三种方式(mysql、mysqli、pdo)
  • 原文地址:https://www.cnblogs.com/linuxprobe-sarah/p/10403706.html
Copyright © 2020-2023  润新知