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_1 | 2.12-2.3.0 | 8核 | 16g | contos7 |
| kafka_2 | 2.12-2.3.0 | 8核 | 16g | contos7 |
| kafka_3 | 2.12-2.3.0 | 8核 | 16g | contos7 |
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-records | batch.size | partition | replication | throughput | records/s | MB/s |
|---|---|---|---|---|---|---|---|
| 1 | 100W | 5000 | 1 | 1 | 30000 | 28420.39 | 18.62 |
| 2 | 100W | 10000 | 1 | 1 | 30000 | 29985.01 | 19.65 |
| 3 | 100W | 20000 | 1 | 1 | 30000 | 29983.21 | 19.64 |
| 4 | 100W | 40000 | 1 | 1 | 30000 | 29982.31 | 19.64 |
| 5 | 100W | 60000 | 1 | 1 | 30000 | 29982.31 | 19.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-records | batch.size | partition | replication | throughput | records/s | MB/s |
|---|---|---|---|---|---|---|---|
| 1 | 1000W | 10000 | 1 | 1 | 100000 | 62436.00 | 40.91 |
| 2 | 1000W | 10000 | 1 | 1 | 200000 | 69896.34 | 45.79 |
| 3 | 1000W | 10000 | 1 | 1 | 250000 | 74023.62 | 48.50 |
| 4 | 1000W | 10000 | 1 | 1 | 300000 | 74013.76 | 48.49 |
| 5 | 1000W | 10000 | 1 | 1 | 350000 | 73410.66 | 48.10 |
| 6 | 1000W | 10000 | 1 | 1 | 400000 | 68582.87 | 44.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-records | batch.size | throughput | replication | partition | records/s | MB/s |
|---|---|---|---|---|---|---|---|
| 1 | 1000W | 10000 | 300000 | 3 | 3 | 91554.96 | 59.98 |
| 2 | 1000W | 10000 | 300000 | 3 | 6 | 140386.34 | 91.98 |
| 3 | 1000W | 10000 | 300000 | 3 | 9 | 168217.06 | 110.21 |
| 4 | 1000W | 10000 | 300000 | 3 | 12 | 179878.76 | 117.85 |
| 5 | 1000W | 10000 | 300000 | 3 | 15 | 187698.25 | 122.98 |
| 6 | 1000W | 10000 | 300000 | 3 | 18 | 179288.58 | 117.47 |
| 7 | 1000W | 10000 | 300000 | 3 | 21 | 164790.79 | 107.97 |
测试总结:
分区数为15时,吞吐量达到最优,后续趋于稳定。这是由于网络和磁盘的问题可能会有一些起伏。
3.4 线程数
| 序号 | num-records | batch.size | partition | replication | thread | s |
|---|---|---|---|---|---|---|
| 1 | 9999999 | 10000 | 15 | 3 | 1 | 66.722 |
| 2 | 9999999 | 10000 | 15 | 3 | 3 | 77.221 |
| 3 | 9999996 | 10000 | 15 | 3 | 6 | 77.948 |
| 4 | 9999999 | 10000 | 15 | 3 | 9 | 75.161 |
| 5 | 9999990 | 10000 | 15 | 3 | 15 | 76.057 |
| 6 | 9999990 | 10000 | 15 | 3 | 18 | 76.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
| messages | partition | threads | records/s | MB/s |
|---|---|---|---|---|
| 100W | 15 | 1 | 20.26 | 655307.99 |
| 100W | 15 | 3 | 22.27 | 719424.46 |
| 100W | 15 | 6 | 22.27 | 727802.03 |
| 100W | 15 | 9 | 21.74 | 719424.46 |
| 100W | 15 | 12 | 21.47 | 707213.57 |
| 100W | 15 | 15 | 20.48 | 671140.93 |
| 100W | 15 | 18 | 20.75 | 680735.19 |
测试总结:
向一个拥有15个分区,3个副本的topic发送100万的消息记录,在线程数为6时,每秒发送的消息记录达到最佳值,随着线程数的增加,每秒消费的消息缓慢减小。(常规来说,当线程数与消费分区一致时,吞吐量达到最大)