首页 > 技术文章 > 使用kafka自带脚本进行压力测试

XY-Heruo 2021-04-27 15:52 原文

前言

kafka官方自带压力测试脚本:

  • 消费者压力测试:kafka-consumer-perf-test.sh
  • 生产者压力测试:kafka-producer-perf-test.sh

测试节点:

  • 172.50.13.103
  • 172.50.13.104
  • 172.50.13.105

生产者压力测试

/home/web/kafka/bin/kafka-producer-perf-test.sh --topic test --record-size 100 --num-records 100000 --throughput -1 --producer-props bootstrap.servers=172.50.13.103:9092,172.50.13.104:9092,172.50.13.105:9092

命令参数说明:

  • --topic:主题名
  • --record-size:单条消息的数据大小,单位字节
  • --num-records:总消息数
  • --throughput:每秒消息数,-1表示不限制
  • bootstrap.servers:节点和端口

结果:

100000 records sent, 42337.002540 records/sec (40.38 MB/sec), 465.00 ms avg latency, 1121.00 ms max latency, 392 ms 50th, 1023 ms 95th, 1110 ms 99th, 1120 ms 99.9th.

结果说明:

  • 吞吐量:40.38 MB/sec
  • 每次写入的平均延迟:465.00 ms
  • 最大延迟:1121.00 ms

将近0.5秒的写入延迟,算是比较低的性能了。

消费者压力测试

/home/web/kafka/bin/kafka-consumer-perf-test.sh --broker-list 172.50.13.103:9092,172.50.13.104:9092,172.50.13.105:9092 --topic=test --fetch-size 10000 -messages 100000 --threads 1

命令参数说明:

  • --fetch-size:指定每次fetch的数据的大小
  • --messages:总共要消费的消息个数

结果:

start.time, end.time, data.consumed.in.MB, MB.sec, data.consumed.in.nMsg, nMsg.sec, rebalance.time.ms, fetch.time.ms, fetch.MB.sec, fetch.nMsg.sec
2021-04-27 15:35:34:005, 2021-04-27 15:35:35:429, 13.6017, 9.5517, 100000, 70224.7191, 1619508934406, -1619508932982, -0.0000, -0.0001

结果说明:

  • 共消费数据13.6017 MB
  • 吞吐量:9.5517 MB/sec
  • 总共消费消息量:100000
  • 平均每秒消费:70224.7191 nMsg/Sec

平均每秒消费数也比较低。

推荐阅读