美文网首页
kafka 压力测试

kafka 压力测试

作者: 癞痢头 | 来源:发表于2021-05-28 22:29 被阅读0次

    在总体上或在硬件上了解Kafka的性能是容量规划的重要组成部分。使用不同的消息大小,保留时间,分区,副本因子,网络速度,甚至同步还是异步,都很难计算大小。做出如此多的决定,但是您实际上可以期望什么样的表现呢?

    本文使用kafka自带了压力测试的工具,对自建kafka进行基本测试, 以了解其性能

    硬件规格

    配置项
    CPU平台 Intel/Cascadelake
    镜像 CentOS 8.0 64位
    CPU 2核
    内存 4G
    系统盘容量 40GB
    数据盘容量 100GB
    网络 内网带宽 200M/s

    测试用例 perf_test_v2.sh

    测试用例是使用kafka自带工具的bash命令组合,分别使用10w,100w和1000w的总消息数量发送, 以下是测试内容脚本,修改了zookeeper 地址后,可直接使用

    #!/usr/bin/env bash
    
    echo ">> 10w 写入测试"
    echo ">> time ./bin/kafka-producer-perf-test.sh --topic test_perf --num-records 100000 --record-size 1000  --throughput 2000 --producer-props bootstrap.servers=localhost:9092"
    time ./bin/kafka-producer-perf-test.sh --topic test_perf --num-records 100000 --record-size 1000  --throughput 2000 --producer-props bootstrap.servers=localhost:9092
    echo 
    
    
    echo ">> 100w 写入测试"
    echo ">> time ./bin/kafka-producer-perf-test.sh --topic test_perf --num-records 1000000 --record-size 2000  --throughput 5000 --producer-props bootstrap.servers=localhost:9092"
    time ./bin/kafka-producer-perf-test.sh --topic test_perf --num-records 1000000 --record-size 2000  --throughput 5000 --producer-props bootstrap.servers=localhost:9092
    echo 
    
    echo ">> 1000w 写入测试"
    echo ">> time ./bin/kafka-producer-perf-test.sh --topic test_perf --num-records 10000000 --record-size 2000  --throughput 10000 --producer-props bootstrap.servers=localhost:9092"
    time ./bin/kafka-producer-perf-test.sh --topic test_perf --num-records 10000000 --record-size 2000  --throughput 10000 --producer-props bootstrap.servers=localhost:9092
    echo 
    
    echo ">> 10w 消费测试"
    echo ">> time ./bin/kafka-consumer-perf-test.sh --zookeeper localhost:2181 --topic test_perf --fetch-size 1048576 --messages 1000000 --threads 1"
    time ./bin/kafka-consumer-perf-test.sh --zookeeper localhost:2181 --topic test_perf --fetch-size 1048576 --messages 1000000 --threads 1
    echo 
    
    echo ">> 100w 消费测试"
    echo ">> time ./bin/kafka-consumer-perf-test.sh --zookeeper localhost:2181 --topic test_perf --fetch-size 1048576 --messages 10000000 --threads 1"
    time ./bin/kafka-consumer-perf-test.sh --zookeeper localhost:2181 --topic test_perf --fetch-size 1048576 --messages 10000000 --threads 1
    echo 
    
    echo ">> 1000W 消费测试"
    echo ">> time ./bin/kafka-consumer-perf-test.sh --zookeeper localhost:2181 --topic test_perf --fetch-size 1048576 --messages 10000000 --threads 1"
    time ./bin/kafka-consumer-perf-test.sh --zookeeper localhost:2181 --topic test_perf --fetch-size 1048576 --messages 10000000 --threads 1
    echo 
    

    测试结果

    在命令行执行测试用例 : nohup ./perf_test_v2.sh &>> perf_test2.log &

    实际的测试结果如图 :


    生产者压测 消费者压测

    为方便展示,本文将测试结果列为表格方便对比

    生产测试结果:

    用例 耗时 单次并发发送 最终结果
    10w 写入测试 0m50.926s 10002 records sent, 2000.0 records/sec (1.91 MB/sec), 3.3 ms avg latency, 168.0 max latency. 100000 records sent, 1999.880007 records/sec (1.91 MB/sec), 0.58 ms avg latency, 168.00 ms max latency, 0 ms 50th, 1 ms 95th, 4 ms 99th, 69 ms 99.9th.
    100w 写入测试 3m20.951s 25005 records sent, 5001.0 records/sec (9.54 MB/sec), 0.3 ms avg latency, 3.0 max latency. 1000000 records sent, 4999.600032 records/sec (9.54 MB/sec), 0.38 ms avg latency, 85.00 ms max latency, 0 ms 50th, 1 ms 95th, 1 ms 99th, 23 ms 99.9th.
    1000w 写入测试 16m40.983s 50016 records sent, 10003.2 records/sec (19.08 MB/sec), 0.3 ms avg latency, 6.0 max latency. 10000000 records sent, 9999.370040 records/sec (19.07 MB/sec), 0.38 ms avg latency, 91.00 ms max latency, 0 ms 50th, 1 ms 95th, 1 ms 99th, 7 ms 99.9th.

    消费测试结果:

    用例 耗时 开始时间 结束时间 data.consumed(MB) 速率 (MB/s) data.consumed(count) 速率 (条/s)
    10w 消费测试 0m17.677s 2021-05-28 15:48:46:857 2021-05-28 15:49:00:742 1811.9812 130.4992 1000000 72020.1656
    100w 消费测试 2m5.422s 2021-05-28 15:49:04:185 2021-05-28 15:51:06:104 18978.1189 155.6617 10000000 82021.6701
    1000w 消费测试 2m12.896s 2021-05-28 15:51:10:076 2021-05-28 15:53:19:590 18978.1189 146.5333 10000000 77211.7300

    测试脚本

    测试所使用的脚本都来自于kafka自带工具中,下面是一些对于工具使用的介绍

    • kafka-producer-perf-test.sh
      生产者压测工具
    --topic  测试topic 
    --num-records 总测试消息数量 
    --record-size 单个消息大小 bytes
    --throughput 单次并发数量
    
    • kafka-consumer-perf-test.sh
      消费者压测工具
    --batch-size        单次写入数据大小
    --broker-list 
    --fetch-size        单次请求数据量 (default: 1048576)
    --from-latest  
    --group             消费组ID (default:perf-consumer-88191)
    --message-size      <Integer: size>  单条消息大小(default:100)
    --messages          <Long: count>  必须参数: 消费或发送消息总数
    --num-fetch-threads <Integer: count>   fetch线程数量 (default: 1)
    --threads           <Integer: count>     处理线程数量 (default: 10)
    --topic             <String: topic>                  REQUIRED: 
    --zookeeper         <String: urls>               REQUIRED 
    

    相关文章

      网友评论

          本文标题:kafka 压力测试

          本文链接:https://www.haomeiwen.com/subject/rkyesltx.html