Skip to content

基准测试

使用 redis-benchmark 工具

官方 Redis Benchmark 工具参考

基本使用

从容器中复制 redis-benchmark 工具

注意:从容器中复制的 redis-benchmark 不能在 CentOS8 运行,报告错误 "./redis-benchmark: /lib64/libm.so.6: version `GLIBC_2.29' not found (required by ./redis-benchmark)",只能使用 Ubuntu 运行 redis-benchmark。

bash
docker compose cp redis:/usr/local/bin/redis-benchmark .

在安静模式下,向 Redis 服务器发送 100,000 个请求,并只显示每秒的请求数和每秒传输的数据量作为性能评估指标。

bash
$ redis-benchmark -q -n 100000 -h 192.168.1.185 -a 123456
PING_INLINE: 108932.46 requests per second, p50=0.271 msec                    
PING_MBULK: 145985.41 requests per second, p50=0.263 msec                    
SET: 131061.59 requests per second, p50=0.295 msec                    
GET: 139275.77 requests per second, p50=0.271 msec                    
INCR: 131578.95 requests per second, p50=0.303 msec                    
LPUSH: 125786.16 requests per second, p50=0.311 msec                    
RPUSH: 129366.11 requests per second, p50=0.303 msec                    
LPOP: 126103.41 requests per second, p50=0.303 msec                    
RPOP: 107411.38 requests per second, p50=0.359 msec                    
SADD: 138696.25 requests per second, p50=0.263 msec                    
HSET: 136798.91 requests per second, p50=0.279 msec                    
SPOP: 133689.83 requests per second, p50=0.287 msec                    
ZADD: 134952.77 requests per second, p50=0.279 msec                    
ZPOPMIN: 134770.89 requests per second, p50=0.279 msec                    
LPUSH (needed to benchmark LRANGE): 130208.34 requests per second, p50=0.303 msec                    
LRANGE_100 (first 100 elements): 69686.41 requests per second, p50=0.527 msec                   
LRANGE_300 (first 300 elements): 26288.12 requests per second, p50=1.031 msec                   
LRANGE_500 (first 500 elements): 16926.20 requests per second, p50=1.519 msec                   
LRANGE_600 (first 600 elements): 14513.79 requests per second, p50=1.735 msec                   
MSET (10 keys): 98231.83 requests per second, p50=0.455 msec
  • -n 100000 表示请求总数(默认100000)
  • -q 表示安静。仅显示查询/秒值

使用 -t 选项选择仅一部分测试

bash
$ redis-benchmark -t set,lpush -n 100000 -q -h 192.168.1.185 -a 123456
SET: 107758.62 requests per second, p50=0.279 msec                   
LPUSH: 127388.53 requests per second, p50=0.327 msec
  • 在上面的例子中,我们要求在安静模式下仅运行测试 SET 和 LPUSH 命令(参见 -q 开关)。
  • -t 表示仅运行以逗号分隔的测试列表。测试名称与输出的名称相同。

直接指定要进行基准测试的命令

bash
$ redis-benchmark -n 1000000 -q -h 192.168.1.185 -a 123456 script load "redis.call('set','foo','bar')"
script load redis.call('set','foo','bar'): 103950.10 requests per second, p50=0.295 msec
bash
$ redis-benchmark -n 1000000 -q -h 192.168.1.185 -a 123456 script load "local uuidStr='xxxxxxxxxxxxxxxxxxxx';redis.call('set', uuidStr, uuidStr);local uuidStrResult=redis.call('get', uuidStr);return uuidStrResult"

选择 Key 空间的大小

默认情况下,基准测试针对单个键运行。在 Redis 中,由于它是一个内存系统,因此这种合成基准测试与真实基准测试之间的差异并不大,但是可以使用较大的键空间来强调缓存未命中,并且通常可以模拟更真实的工作负载。

这可以通过使用 -r 开关来实现。例如,如果我想运行一百万个 SET 操作,对 100k 个可能键中的每个操作使用一个随机键。

bash
$ redis-cli -h 192.168.1.185 -a 123456 flushall
OK

$ redis-benchmark -t set -r 100000 -n 1000000 -h 192.168.1.185 -a 123456
====== SET ======
  1000000 requests completed in 7.37 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.64% <= 1 milliseconds
99.89% <= 2 milliseconds
99.99% <= 3 milliseconds
100.00% <= 3 milliseconds
135611.61 requests per second

$ redis-cli -h 192.168.1.185 -a 123456 dbsize
(integer) 99998
  • -r 100000 表示执行 SET 命令随机生成约 10w 个 key。

__rand_int__ 使用

参考链接

基准测试将使用 12 位数字扩展参数内的字符串 __rand_int__,范围从 0 到 keyspacelen-1。

bash
redis-benchmark -n 1000000 -q -h 192.168.1.190 -a 123456 -r 5 set __rand_int__ __rand_int__

-r 表示测试期间共生成 5 个 key,__rand_int__ 占位符会被随机 key 替换。

使用 pipelining

默认情况下,每个客户端(如果没有使用 -c 另行指定,基准测试将模拟 50 个客户端)仅在收到上一个命令的回复时才发送下一个命令,这意味着服务器可能需要读取调用才能从每个客户端读取每个命令。此外,RTT 也是需要考虑的。

Redis 支持流水线,因此可以一次发送多个命令,这是现实世界应用程序经常利用的功能。Redis 流水线能够显著提高服务器每秒能够提供的操作数。

使用 16 个命令的流水线运行基准测试的示例:

bash
$ redis-benchmark -n 1000000 -t set,get -P 16 -q -h 192.168.1.185 -a 123456
SET: 773395.19 requests per second, p50=0.943 msec                    
GET: 1438848.88 requests per second, p50=0.391 msec
  • -P 16 表示客户端并行连接的管道(pipeline)数量。管道允许客户端一次性发送多个命令到服务器,服务器可以一次性返回所有命令的回复,这可以减少网络往返时间,提高吞吐量。这里设置为 16,意味着每个客户端将使用 16 个管道。

综合案例

bash
redis-benchmark -t set -r 10000 -n 1000000 -c 128 --threads 8 -q -l -h 192.168.1.190 -a 123456
  • -c 128 表示并发连接数为 128
  • --threads 8 表示并发线程数为 8
  • -q 表示安静。仅显示查询/秒值
  • -l 表示循环。永远运行测试

测试 Redis 单机

测试 set 命令

步骤如下:

  1. 参考 链接 启动单机版 Redis(运行单机版 Redis 的实例为 4C6G,提醒:经过测试单机版 Redis 只使用 1 个 CPU,所以多核 CPU 实例对单机版 Redis 性能提升没有帮助)

  2. 执行基准测试

    bash
    $ redis-benchmark -q -t set -r 300 -n 1000000 -c 256 --threads 8 -h 192.168.1.185 -p 6379 -a 123456
    SET: 147536.16 requests per second, p50=1.503 msec
  3. 结论:单机 Redis QPS 约为 15w,被压测的 Redis 进程 CPU 利用率为 94%。

测试 Lua 脚本

步骤如下:

  1. 参考 链接 启动单机版 Redis(运行单机版 Redis 的实例为 4C6G)

  2. 测试 script load 和 evalsha

    • 在 redis cli 中使用 script load 加载脚本到缓存中

      bash
      > script load "local uuidStr=ARGV[1];redis.call('set', uuidStr, uuidStr);local uuidStrResult=redis.call('get', uuidStr);return uuidStrResult"
      "d537bb8da0cbea70244fce7eac2c3e4b531ded31"
    • 使用非管道基准测试 Lua 脚本

      bash
      > redis-benchmark -n 1000000 -q -h 192.168.1.190 -a 123456 -r 10000 evalsha d537bb8da0cbea70244fce7eac2c3e4b531ded31 0 __rand_int__
      evalsha d537bb8da0cbea70244fce7eac2c3e4b531ded31 0 __rand_int__: 101296.60 requests per second, p50=0.423 msec
    • 使用管道基准测试 Lua 脚本

      bash
      > redis-benchmark -n 1000000 -q -h 192.168.1.190 -a 123456 -r 10000 -P 16 evalsha d537bb8da0cbea70244fce7eac2c3e4b531ded31 0 __rand_int__
      evalsha d537bb8da0cbea70244fce7eac2c3e4b531ded31 0 __rand_int__: 255885.36 requests per second, p50=2.887 msec
  3. 测试 eval

    • 使用非管道基准测试 Lua 脚本

      bash
      > redis-benchmark -n 1000000 -q -h 192.168.1.190 -a 123456 -r 10000 eval "local uuidStr=ARGV[1];redis.call('set', uuidStr, uuidStr);local uuidStrResult=redis.call('get', uuidStr);return uuidStrResult" 0 __rand_int__
      eval local uuidStr=ARGV[1];redis.call('set', uuidStr, uuidStr);local uuidStrResult=redis.call('get', uuidStr);return uuidStrResult 0 __rand_int__: 96880.45 requests per second, p50=0.455 msec
    • 使用管道基准测试 Lua 脚本

      bash
      > redis-benchmark -n 1000000 -q -h 192.168.1.190 -a 123456 -r 10000 -P 16 eval "local uuidStr=ARGV[1];redis.call('set', uuidStr, uuidStr);local uuidStrResult=redis.call('get', uuidStr);return uuidStrResult" 0 __rand_int__
      eval local uuidStr=ARGV[1];redis.call('set', uuidStr, uuidStr);local uuidStrResult=redis.call('get', uuidStr);return uuidStrResult 0 __rand_int__: 198019.80 requests per second, p50=3.719 msec
  4. 结论:使用管道基准测试性能非常高。

测试 Redis 集群

测试 set 命令

步骤如下:

  1. 参考 链接 启动 Redis 集群(运行集群版 Redis 的实例为 8C8G)

  2. 执行基准测试

    bash
    $ redis-benchmark -q -t set -r 300 -n 10000000 -c 256 --threads 8 -h 192.168.1.185 -p 6380 --cluster
    Cluster has 3 master nodes:
    
    Master 0: 0a61eaa40616c30e785a49ce99e8bb93c65d3e22 192.168.1.185:6382
    Master 1: 6d9338f3deef13eaac9ad512dbee497d1485c5c8 192.168.1.185:6381
    Master 2: c1185ebb0c1acd0f8419fe65a8f45abebfee38ed 192.168.1.185:6380
    
    SET: 372689.31 requests per second, p50=0.631 msec
  3. 结论:Redis 集群 QPS 约为 37w,被压测的 3 个 Redis 进程 CPU 利用率为 80%。

测试 Lua 脚本

注意:使用下面脚本测试报错,所以无法使用 redis-benchmark 测试 Redis 集群 Lua 脚本性能。参考本站 链接 使用 JMH 测试。

步骤如下:

  1. 参考 链接 启动 Redis 集群(运行集群版 Redis 的实例为 8C8G)

  2. 测试 eval

    • 使用非管道基准测试 Lua 脚本

      bash
      > redis-benchmark -q -r 10000 -n 1000000 -c 128 --threads 8 -h 192.168.1.185 -p 6380 --cluster eval "local uuidStr=ARGV[1];redis.call('set', uuidStr, uuidStr);local uuidStrResult=redis.call('get', uuidStr);return uuidStrResult" 1 __rand_int__ __rand_int__

使用 JMeter 自定义基准测试工具

详细用法请参考本站 示例

测试 Redis 单机

步骤如下:

  1. 参考 链接 启动单机版 Redis(运行单机版 Redis 的实例为 4C6G)

  2. 编译和发布插件到 JMeter 目录中

    bash
    ./deploy-plugin.sh
  3. 测试计划使用 com.future.demo.RedisBenchmarkSetByUsingJedisSampler

  4. 执行测试

    bash
    $ jmeter -n -t jmeter.jmx
    summary = 8287194 in 00:00:52 = 158801.1/s Avg:     1 Min:     0 Max:    26 Err:     0 (0.00%)
  5. 结论:单机版的 Redis QPS 约为 16w,被压测的 Redis 进程 CPU 利用率为 91%。

测试 Redis 集群

步骤如下:

  1. 参考 链接 启动 Redis 集群(运行集群版 Redis 的实例为 8C8G)

  2. 编译和发布插件到 JMeter 目录中

    bash
    ./deploy-plugin.sh
  3. 测试计划使用 com.future.demo.RedisBenchmarkSetByUsingJedisSampler

  4. 执行测试

    bash
    $ jmeter -n -t jmeter.jmx
    summary = 17452153 in 00:00:57 = 304777.2/s Avg:     0 Min:     0 Max:   100 Err:     0 (0.00%)
  5. 结论:Redis 集群 QPS 约为 30w,被压测的 3 个 Redis 进程 CPU 利用率为 78%。通过和 redis-benchmark Redis 集群基准测试对比,JMeter 基准测试性能不如 redis-benchmark 性能,JMeter 不能充分发挥压力机的性能。

JMH 基准测试

详细用法请参考本站:

测试 Redis 单机

测试 set、Lua 脚本步骤如下:

  1. 参考 链接 启动单机版的 Redis 服务(运行单机版 Redis 的实例为 4C6G)

  2. 分别运行示例中的 JmhBenchmarkTests 测试

    bash
    # Lettuce 测试结果
    Benchmark                         Mode  Cnt       Score       Error  Units
    JmhBenchmarkTests.testLuaScript  thrpt    3  147567.633 ± 23428.804  ops/s
    JmhBenchmarkTests.testSet        thrpt    3  165011.457 ± 10084.365  ops/s
    
    # Jedis 测试结果
    Benchmark                         Mode  Cnt       Score       Error  Units
    JmhBenchmarkTests.testLuaScript  thrpt    3   96440.611 ± 36275.595  ops/s
    JmhBenchmarkTests.testSet        thrpt    3  149788.054 ± 37734.204  ops/s
    
    # RedisTemplate 测试结果
    Benchmark                         Mode  Cnt      Score       Error  Units
    JmhBenchmarkTests.testLuaScript  thrpt    3  88135.771 ± 34605.815  ops/s
    JmhBenchmarkTests.testSet        thrpt    3  90674.203 ± 32400.563  ops/s

测试 Redis7 Function 步骤如下:

  1. 参考 链接 启动单机版的 Redis 服务(运行单机版 Redis 的实例为 4C6G)

  2. 手动加载 Function 到 Redis 中

    functions.lua 内容如下:

    lua
    #!lua name=mylib
    
    local function my_test1(keys, args)
      local uuidStr=args[1]
      redis.call("set", uuidStr, uuidStr)
      local uuidStrResult=redis.call("get", uuidStr)
      return uuidStrResult
    end
    
    redis.register_function('my_test1', my_test1)

    加载 function 到 Redis 中

    bash
    cat functions.lua | redis-cli -x -a 123456 function load replace
  3. 取消 Lettuce 基准测试示例中的 JmhBenchmarkTests#testFunction 注释即可进行测试。

  4. 测试结果如下:

    Benchmark                         Mode  Cnt       Score       Error  Units
    JmhBenchmarkTests.testFunction   thrpt    3  142758.257 ± 22038.451  ops/s
    JmhBenchmarkTests.testLuaScript  thrpt    3  142620.876 ± 42896.186  ops/s
    JmhBenchmarkTests.testSet        thrpt    3  157310.504 ± 33322.356  ops/s
  5. 结论:Redis Function 性能没有明显高于 Lua 脚本。

测试 Redis 集群

测试 set、Lua 脚本步骤如下:

  1. 参考 链接 启动 Redis 集群(运行集群版 Redis 的实例为 8C8G)

  2. 分别运行示例中的 JmhBenchmarkTests 测试

    bash
    # Lettuce 测试结果
    Benchmark                         Mode  Cnt       Score        Error  Units
    JmhBenchmarkTests.testLuaScript  thrpt    3  339170.612 ± 124063.615  ops/s
    JmhBenchmarkTests.testSet        thrpt    3  331483.703 ± 460164.316  ops/s
    
    # Jedis 测试结果
    Benchmark                         Mode  Cnt       Score        Error  Units
    JmhBenchmarkTests.testLuaScript  thrpt    3  216187.915 ±  88286.922  ops/s
    JmhBenchmarkTests.testSet        thrpt    3  354756.348 ± 248880.508  ops/s
    
    # RedisTemplate 测试结果
    Benchmark                         Mode  Cnt       Score        Error  Units
    JmhBenchmarkTests.testLuaScript  thrpt    3  256954.293 ± 301313.315  ops/s
    JmhBenchmarkTests.testSet        thrpt    3  272224.942 ±  63771.530  ops/s

测试 Redis7 Function 步骤如下:

  1. 参考 链接 启动 Redis 集群(运行集群版 Redis 的实例为 8C8G)

  2. 手动加载 Function 到 Redis 集群中

    functions.lua 内容如下:

    lua
    #!lua name=mylib
    
    local function my_test1(keys, args)
      local uuidStr=args[1]
      redis.call("set", uuidStr, uuidStr)
      local uuidStrResult=redis.call("get", uuidStr)
      return uuidStrResult
    end
    
    redis.register_function('my_test1', my_test1)

    加载 function 到 Redis 中

    bash
    cat functions.lua | redis-cli -p 6380 -x function load replace
    cat functions.lua | redis-cli -p 6381 -x function load replace
    cat functions.lua | redis-cli -p 6382 -x function load replace
  3. 取消 Lettuce 基准测试示例中的 JmhBenchmarkTests#testFunction 注释即可进行测试。

  4. 测试结果如下:

    Benchmark                         Mode  Cnt       Score        Error  Units
    JmhBenchmarkTests.testFunction   thrpt    3  305916.380 ± 503612.450  ops/s
    JmhBenchmarkTests.testLuaScript  thrpt    3  283785.895 ± 380175.650  ops/s
    JmhBenchmarkTests.testSet        thrpt    3  365896.817 ± 348877.540  ops/s
  5. 结论:Redis Function 性能没有明显高于 Lua 脚本。

使用 YCSB 工具

YCSB GitHub

YCSB 全称为 Yahoo Cloud Serving Benchmark。

测试单机版 Redis

步骤如下:

根据官方指引运行 Redis 测试

  1. 参考 链接 启动单机版的 Redis 服务

  2. 克隆 YCSB 源代码

    bash
    git clone https://github.com/brianfrankcooper/YCSB.git
  3. 编译 Redis 测试

    bash
    mvn -pl site.ycsb:redis-binding -am clean package
  4. 修改 workloads/workloada 内容如下:

    properties
    # Copyright (c) 2010 Yahoo! Inc. All rights reserved.                                                                                                                             
    #                                                                                                                                                                                 
    # Licensed under the Apache License, Version 2.0 (the "License"); you                                                                                                             
    # may not use this file except in compliance with the License. You                                                                                                                
    # may obtain a copy of the License at                                                                                                                                             
    #                                                                                                                                                                                 
    # http://www.apache.org/licenses/LICENSE-2.0                                                                                                                                      
    #                                                                                                                                                                                 
    # Unless required by applicable law or agreed to in writing, software                                                                                                             
    # distributed under the License is distributed on an "AS IS" BASIS,                                                                                                               
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or                                                                                                                 
    # implied. See the License for the specific language governing                                                                                                                    
    # permissions and limitations under the License. See accompanying                                                                                                                 
    # LICENSE file.                                                                                                                                                                   
    
    
    # Yahoo! Cloud System Benchmark
    # Workload A: Update heavy workload
    #   Application example: Session store recording recent actions
    #                        
    #   Read/update ratio: 50/50
    #   Default data size: 1 KB records (10 fields, 100 bytes each, plus key)
    #   Request distribution: zipfian
    
    # Redis 基准测试时表示使用 100 个 Key
    recordcount=100
    # 总共执行 100w 此操作
    operationcount=1000000
    # 64 条并发测试线程
    threadcount=64
    workload=site.ycsb.workloads.CoreWorkload
    
    readallfields=true
    
    # 读(get)操作比例为 0
    readproportion=0
    # 更新(set)操作比例为 1
    updateproportion=1
    scanproportion=0
    insertproportion=0
    
    requestdistribution=zipfian
  5. 参考 链接 配置 ClusterSSH 客户端

  6. 使用 ClusterSSH 建立多个连接到压力机以同时执行多个 YCSB 客户端

    bash
    $ cssh -l dexterleslie 192.168.1.181 192.168.1.181 192.168.1.181 192.168.1.181 192.168.1.181 192.168.1.181 192.168.1.181 -a "bash --login -i"
    
    # 手动切换到 YCSB 所在的目录,例如:cd ~/workspace-git/YCSB
    
    # 建立多个 cssh 连接后同时运行 YCSB 客户端
    $ ./bin/ycsb run redis -s -P workloads/workloada -p "redis.host=192.168.1.185" -p "redis.port=6379" -p "redis.password=123456" > outputRun.txt
    2025-03-19 00:00:08:617 47 sec: 1000000 operations; 20909.23 current ops/sec; [CLEANUP: Count=64, Max=963, Min=22, Avg=64.2, 90=74, 99=963, 99.9=963, 99.99=963] [UPDATE: Count=147658, Max=12559, Min=859, Avg=2976.37, 90=3923, 99=4479, 99.9=7579, 99.99=10807]
    2025-03-19 00:00:08:930 47 sec: 1000000 operations; 21588.96 current ops/sec; [CLEANUP: Count=64, Max=1120, Min=21, Avg=55.12, 90=49, 99=1120, 99.9=1120, 99.99=1120] [UPDATE: Count=154459, Max=11095, Min=493, Avg=2926.15, 90=3865, 99=4435, 99.9=7115, 99.99=10343]
    2025-03-19 00:00:09:044 46 sec: 1000000 operations; 22539.17 current ops/sec; [CLEANUP: Count=64, Max=971, Min=16, Avg=55.41, 90=66, 99=971, 99.9=971, 99.99=971] [UPDATE: Count=149585, Max=11255, Min=96, Avg=2814.46, 90=3773, 99=4451, 99.9=6667, 99.99=10303] 
    2025-03-19 00:00:08:892 47 sec: 1000000 operations; 21207.35 current ops/sec; [CLEANUP: Count=64, Max=993, Min=19, Avg=57.91, 90=70, 99=993, 99.9=993, 99.99=993] [UPDATE: Count=152356, Max=11543, Min=776, Avg=2950.16, 90=3889, 99=4435, 99.9=7155, 99.99=10463]
    2025-03-19 00:00:08:998 46 sec: 1000000 operations; 22008.39 current ops/sec; [CLEANUP: Count=64, Max=761, Min=19, Avg=48.34, 90=58, 99=761, 99.9=761, 99.99=761] [UPDATE: Count=152142, Max=11199, Min=161, Avg=2878.78, 90=3843, 99=4451, 99.9=6967, 99.99=10575]
    2025-03-19 00:00:09:117 46 sec: 1000000 operations; 23430.34 current ops/sec; [CLEANUP: Count=64, Max=794, Min=20, Avg=50.53, 90=59, 99=794, 99.9=794, 99.99=794] [UPDATE: Count=147295, Max=12095, Min=78, Avg=2701.89, 90=3525, 99=4435, 99.9=6951, 99.99=10287] 
    2025-03-19 00:00:08:915 47 sec: 1000000 operations; 21307.61 current ops/sec; [CLEANUP: Count=64, Max=622, Min=20, Avg=49.83, 90=58, 99=622, 99.9=622, 99.99=622] [UPDATE: Count=153739, Max=21007, Min=639, Avg=2947.66, 90=3897, 99=4507, 99.9=7407, 99.99=16463]
  7. 结论:通过 6 个控制台 QPS 输出计算得出单机版的 Redis QPS 约为 15w,被压测的 Redis 进程 CPU 利用率为 91%。

测试 Redis 集群

步骤如下:

根据官方指引运行 Redis 测试

  1. 参考 链接 启动 Redis 集群

  2. 克隆 YCSB 源代码

    bash
    git clone https://github.com/brianfrankcooper/YCSB.git
  3. 编译 Redis 测试

    bash
    mvn -pl site.ycsb:redis-binding -am clean package
  4. 修改 workloads/workloada 内容如下:

    properties
    # Copyright (c) 2010 Yahoo! Inc. All rights reserved.                                                                                                                             
    #                                                                                                                                                                                 
    # Licensed under the Apache License, Version 2.0 (the "License"); you                                                                                                             
    # may not use this file except in compliance with the License. You                                                                                                                
    # may obtain a copy of the License at                                                                                                                                             
    #                                                                                                                                                                                 
    # http://www.apache.org/licenses/LICENSE-2.0                                                                                                                                      
    #                                                                                                                                                                                 
    # Unless required by applicable law or agreed to in writing, software                                                                                                             
    # distributed under the License is distributed on an "AS IS" BASIS,                                                                                                               
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or                                                                                                                 
    # implied. See the License for the specific language governing                                                                                                                    
    # permissions and limitations under the License. See accompanying                                                                                                                 
    # LICENSE file.                                                                                                                                                                   
    
    
    # Yahoo! Cloud System Benchmark
    # Workload A: Update heavy workload
    #   Application example: Session store recording recent actions
    #                        
    #   Read/update ratio: 50/50
    #   Default data size: 1 KB records (10 fields, 100 bytes each, plus key)
    #   Request distribution: zipfian
    
    # Redis 基准测试时表示使用 100 个 Key
    recordcount=100
    # 总共执行 100w 此操作
    operationcount=1000000
    # 64 条并发测试线程
    threadcount=64
    workload=site.ycsb.workloads.CoreWorkload
    
    readallfields=true
    
    # 读(get)操作比例为 0
    readproportion=0
    # 更新(set)操作比例为 1
    updateproportion=1
    scanproportion=0
    insertproportion=0
    
    requestdistribution=zipfian
  5. 参考 链接 配置 ClusterSSH 客户端

  6. 使用 ClusterSSH 建立多个连接到压力机以同时执行多个 YCSB 客户端

    bash
    $ cssh -l dexterleslie 192.168.1.181 192.168.1.181 192.168.1.181 192.168.1.181 192.168.1.181 192.168.1.181 192.168.1.181 -a "bash --login -i"
    
    # 手动切换到 YCSB 所在的目录,例如:cd ~/workspace-git/YCSB
    
    # 建立多个 cssh 连接后同时运行 YCSB 客户端
    $ ./bin/ycsb run redis -s -P workloads/workloada -p "redis.host=192.168.1.185" -p "redis.port=6380" -p "redis.cluster=true" > outputRun.txt
    2025-03-19 00:18:43:813 35 sec: 1000000 operations; 34859.89 current ops/sec; [CLEANUP: Count=64, Max=8895, Min=1041, Avg=3651.41, 90=6155, 99=8895, 99.9=8895, 99.99=8895] [UPDATE: Count=184615, Max=22895, Min=76, Avg=1700.21, 90=3915, 99=7531, 99.9=12863, 99.99=20911]
    2025-03-19 00:18:43:971 35 sec: 1000000 operations; 28691.64 current ops/sec; [CLEANUP: Count=58, Max=16151, Min=1368, Avg=4292.9, 90=8151, 99=16151, 99.9=16151, 99.99=16151] [UPDATE: Count=160802, Max=22687, Min=72, Avg=1723.77, 90=3953, 99=7559, 99.9=13519, 99.99=20255] 
    2025-03-19 00:18:43:973 35 sec: 1000000 operations; 33425.72 current ops/sec; [CLEANUP: Count=64, Max=10855, Min=950, Avg=4005.45, 90=7935, 99=10855, 99.9=10855, 99.99=10855] [UPDATE: Count=190769, Max=27359, Min=72, Avg=1716.11, 90=3953, 99=7539, 99.9=12783, 99.99=25983]
    2025-03-19 00:18:44:008 35 sec: 1000000 operations; 32227.65 current ops/sec; [CLEANUP: Count=64, Max=10663, Min=1142, Avg=3942.39, 90=6631, 99=10663, 99.9=10663, 99.99=10663] [UPDATE: Count=182027, Max=23103, Min=72, Avg=1728.23, 90=3965, 99=7591, 99.9=12359, 99.99=20815] 
    2025-03-19 00:18:43:921 35 sec: 1000000 operations; 34241.66 current ops/sec; [CLEANUP: Count=63, Max=10543, Min=1415, Avg=3426.78, 90=6075, 99=10543, 99.9=10543, 99.99=10543] [UPDATE: Count=192898, Max=32927, Min=68, Avg=1698.6, 90=3923, 99=7463, 99.9=12463, 99.99=22591] 
    2025-03-19 00:18:43:678 35 sec: 1000000 operations; 27430.97 current ops/sec; [CLEANUP: Count=61, Max=10759, Min=1778, Avg=4768.51, 90=7559, 99=10759, 99.9=10759, 99.99=10759] [UPDATE: Count=154879, Max=25903, Min=58, Avg=1763.65, 90=4037, 99=7519, 99.9=11583, 99.99=19423] 
    2025-03-19 00:18:43:968 35 sec: 1000000 operations; 34928.68 current ops/sec; [CLEANUP: Count=64, Max=26463, Min=1440, Avg=3654.56, 90=6503, 99=26463, 99.9=26463, 99.99=26463] [UPDATE: Count=185122, Max=27343, Min=72, Avg=1666.5, 90=3859, 99=7371, 99.9=12671, 99.99=20895]
  7. 结论:通过 6 个控制台 QPS 输出计算得出 Redis 集群 QPS 约为 22w,被压测的 3 个 Redis 进程 CPU 利用率为 65%。通过和 redis-benchmark Redis 集群基准测试对比,JCSB 基准测试性能不如 redis-benchmark 性能,JCSB 不能充分发挥压力机的性能。