Kafka性能压测记录

1,726 阅读6分钟

1. 压测目的

本次性能测试在测试环境下三台集群环境上,对Kafka的生产和消费能力进行压力测试,根据不同量级的消息处理结果,评估Kafka的处理性能是否满足项目需求(该项目期望Kafka能够处理上亿级别的MQ消息)。

2. 内容

2.1 测试方法

具体使用脚本为kafka自带的测试脚本,分别为kafka bin目录下的kafka-producer-perf-test.sh和kafka-consumer-perf-test.sh;通过测试来查看Kafka消费不同数量级别的消息时的处理能力。

2.2 测试环境

主机名Kafka版本CPU内存操作系统
kafka_12.12-2.3.08核16gcontos7
kafka_22.12-2.3.08核16gcontos7
kafka_32.12-2.3.08核16gcontos7

2.3 生产者测试参数

2.4 消费者测试参数

3. 生产者

3.1 batch.size(所处理的数据批次大小)

./bin/kafka-producer-perf-test.sh  --topic test_perf --num-records 1000000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=5000   --throughput 30000

./bin/kafka-producer-perf-test.sh  --topic test_perf --num-records 1000000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=10000   --throughput 30000
    
./bin/kafka-producer-perf-test.sh  --topic test_perf --num-records 1000000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=20000   --throughput 30000
        
./bin/kafka-producer-perf-test.sh  --topic test_perf --num-records 1000000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=40000   --throughput 30000
            
./bin/kafka-producer-perf-test.sh  --topic test_perf --num-records 1000000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=60000   --throughput 30000
                
./bin/kafka-producer-perf-test.sh  --topic test_perf --num-records 1000000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=80000   --throughput 30000

测试结果:

序号num-recordsbatch.sizepartitionreplicationthroughputrecords/sMB/s
1100W5000113000028420.3918.62
2100W10000113000029985.0119.65
3100W20000113000029983.2119.64
4100W40000113000029982.3119.64
5100W60000113000029982.3119.65

测试总结:

​ 在数据批次为1W条时,吞吐量最大,随着数据批次的增大,吞吐量没有明显变化。

3.2 throughput(吞吐量,单位时间内处理消息的数量)

./bin/kafka-producer-perf-test.sh  --topic test_perf --num-records 10000000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=10000 --throughput 100000

./bin/kafka-producer-perf-test.sh  --topic test_perf --num-records 10000000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=10000 --throughput 250000

./bin/kafka-producer-perf-test.sh  --topic test_perf --num-records 10000000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=10000 --throughput 350000

./bin/kafka-producer-perf-test.sh  --topic test_perf --num-records 10000000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=10000 --throughput 400000

./bin/kafka-producer-perf-test.sh  --topic test_perf --num-records 10000000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=10000 --throughput 500000

./bin/kafka-producer-perf-test.sh  --topic test_perf --num-records 10000000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=10000 --throughput 600000

测试结果:

序号num-recordsbatch.sizepartitionreplicationthroughputrecords/sMB/s
11000W100001110000062436.0040.91
21000W100001120000069896.3445.79
31000W100001125000074023.6248.50
41000W100001130000074013.7648.49
51000W100001135000073410.6648.10
61000W100001140000068582.8744.93

测试总结:

​ 并发量在25W时,吞吐量最大,随着并发数的上升,吞吐量没有明显变化。这是因为IO的限制,在高并发的情况下,产生阻塞而导致的。

3.3 partition

bin/kafka-producer-perf-test.sh  --topic test_perf_par_3 --num-records 100000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=10000 --throughput 300000

bin/kafka-producer-perf-test.sh  --topic test_perf_par_6 --num-records 100000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=10000 --throughput 300000

bin/kafka-producer-perf-test.sh  --topic test_perf_par_9 --num-records 100000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=10000 --throughput 300000

bin/kafka-producer-perf-test.sh  --topic test_perf_par_12 --num-records 100000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=10000 --throughput 300000

bin/kafka-producer-perf-test.sh  --topic test_perf_par_15 --num-records 100000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=10000 --throughput 300000

bin/kafka-producer-perf-test.sh  --topic test_perf_par_18 --num-records 100000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=10000 --throughput 300000

bin/kafka-producer-perf-test.sh  --topic test_perf_par_21 --num-records 100000 --record-size 687  --producer-props   bootstrap.servers=10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092  batch.size=10000 --throughput 300000

测试结果

序号num-recordsbatch.sizethroughputreplicationpartitionrecords/sMB/s
11000W100003000003391554.9659.98
21000W1000030000036140386.3491.98
31000W1000030000039168217.06110.21
41000W10000300000312179878.76117.85
51000W10000300000315187698.25122.98
61000W10000300000318179288.58117.47
71000W10000300000321164790.79107.97

测试总结:

​ 分区数为15时,吞吐量达到最优,后续趋于稳定。这是由于网络和磁盘的问题可能会有一些起伏。

3.4 线程数

序号num-recordsbatch.sizepartitionreplicationthreads
1999999910000153166.722
2999999910000153377.221
3999999610000153677.948
4999999910000153975.161
59999990100001531576.057
69999990100001531876.904

测试总结:

​ 向一个拥有15个分区,3个副本的topic发送999万的消息记录,在线程数为9时,每秒发送的消息记录达到最佳值,随着线程数的增加,每秒消息缓慢减小。这里观察到提高produce的线程数,对吞吐量性能影响并不明显。

4. 消费者

线程数

./bin/kafka-consumer-perf-test.sh --broker-list 10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092 --timeout 100000 --topic test_perf_par_15 --group g1 --messages 1000000  --threads 1 
    
./bin/kafka-consumer-perf-test.sh --broker-list 10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092 --timeout 1000000 --topic test_perf_par_15 --group g1 --messages 1000000  --threads 3 
        
./bin/kafka-consumer-perf-test.sh --broker-list 10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092 --timeout 100000 --topic test_perf_par_15 --group g1 --messages 1000000  --threads 6 
            
./bin/kafka-consumer-perf-test.sh --broker-list 10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092 --timeout 100000 --topic test_perf_par_15 --group g1 --messages 1000000  --threads 9 

./bin/kafka-consumer-perf-test.sh --broker-list 10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092 --timeout 100000 --topic test_perf_par_15 --group g1 --messages 1000000  --threads 12

./bin/kafka-consumer-perf-test.sh --broker-list 10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092 --timeout 100000 --topic test_perf_par_15 --group g1 --messages 1000000  --threads 15

./bin/kafka-consumer-perf-test.sh --broker-list 10.2.15.142:9092,10.2.15.175:9092,10.2.15.167:9092 --timeout 100000 --topic test_perf_par_15 --group g1 --messages 1000000  --threads 18
messagespartitionthreadsrecords/sMB/s
100W15120.26655307.99
100W15322.27719424.46
100W15622.27727802.03
100W15921.74719424.46
100W151221.47707213.57
100W151520.48671140.93
100W151820.75680735.19

测试总结:

​ 向一个拥有15个分区,3个副本的topic发送100万的消息记录,在线程数为6时,每秒发送的消息记录达到最佳值,随着线程数的增加,每秒消费的消息缓慢减小。(常规来说,当线程数与消费分区一致时,吞吐量达到最大)