kafka性能测试

tech2025-12-09  4

一、介绍

Kafka官方在安装包的bin目录下提供了kafka-producer-perf-test.sh和kafka-consumer-perf-test.sh两个压力测试脚本,分别用于测试生产者和消费者的性能。通过Kafka压力测试脚本,能够得知Kafka集群的性能瓶颈所在(CPU/内存/网络带宽)等,在通常情况下Kafka集群的性能瓶颈是网络带宽

二、生产者压力测试

创建一个主题test

./kafka-topics.sh --create --zookeeper 116.62.13.104:2181 --topic test --partitions 2 --replication-factor 1

开始测试:

topic指定消息存放的topic :test record-size是一条信息有多大(单位是Byte):200B num-records是总共发送多少条信息 :10000 throughput是每秒多少条信息

./kafka-producer-perf-test.sh --topic test --record-size 200 --num-records 10000 --throughput 1000 --producer-props bootstrap.servers=172.30.118.68:9092 1791 records sent, 330.5 records/sec (0.06 MB/sec), 1465.8 ms avg latency, 3629.0 max latency. 1078 records sent, 208.8 records/sec (0.04 MB/sec), 5392.9 ms avg latency, 7718.0 max latency. 1848 records sent, 308.9 records/sec (0.06 MB/sec), 9319.5 ms avg latency, 11853.0 max latency. 1386 records sent, 261.9 records/sec (0.05 MB/sec), 13290.8 ms avg latency, 15757.0 max latency. 1078 records sent, 191.8 records/sec (0.04 MB/sec), 17191.0 ms avg latency, 20301.0 max latency. 924 records sent, 181.4 records/sec (0.03 MB/sec), 21931.1 ms avg latency, 24458.0 max latency. 770 records sent, 138.9 records/sec (0.03 MB/sec), 26450.5 ms avg latency, 29244.0 max latency. 10000 records sent, 235.726746 records/sec (0.04 MB/sec), 13813.99 ms avg latency, 32619.00 ms max latency, 12140 ms 50th, 31488 ms 95th, 32521 ms 99th, 32610 ms 99.9th.

10000 records sent, 235.726746 records/sec (0.04 MB/sec), 13813.99 ms avg latency, 32619.00 ms max latency, 12140 ms 50th, 31488 ms 95th, 32521 ms 99th, 32610 ms 99.9th.

结果分析: 发送记录数10000条, 每秒发送记录数235.726746条, 每秒发送数据量0.04 MB, 平均每条记录延迟 13813.99ms, 最大延迟 32619.00ms

三、消费者压力测试

zookeeper指定zookeeper集群, topic指定消费的topic, fetch-size指定每次取出的数据大小(单位为Byte) messages总共消费的消息个数 threads 线程数量

./kafka-consumer-perf-test.sh --zookeeper 116.62.13.104:2181 --topic test --fetch-size 200 --messages 10000 --threads 1 start.time, end.time, data.consumed.in.MB, MB.sec, data.consumed.in.nMsg, nMsg.sec 2020-09-05 16:57:13:685, 2020-09-05 16:57:30:844, 1.9073, 0.1112, 10000, 582.7845

结果分析: 本次消费开始时间2020-09-05 16:57:13:685, 本次消费结束时间2020-09-05 16:57:30:844, 消费数据量 1.9073MB, 平均每秒吞吐 0.1112MB/s, 消费记录数 10000条, 平均每秒消费 582.7845条

最新回复(0)