4.2 consumer测试
4.2.1 thread
- 测试脚本
./kafka-consumer-perf-test.sh --zookeeper 110.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_kafka_perf1 --fetch-size 1048576 --messages 100000 --threads 1 --hide-header --num-fetch-threads 1
./kafka-consumer-perf-test.sh --zookeeper 110.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_kafka_perf1 --fetch-size 1048576 --messages 100000 --threads 4 --hide-header --num-fetch-threads 1
./kafka-consumer-perf-test.sh --zookeeper 110.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_kafka_perf1 --fetch-size 1048576 --messages 100000 --threads 7 --hide-header --num-fetch-threads 1
./kafka-consumer-perf-test.sh --zookeeper 110.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_kafka_perf1 --fetch-size 1048576 --messages 100000 --threads 10 --hide-header --num-fetch-threads 1
- 测试结果
Threads | fetch-size | partition | replication | fetch-threads | MB/S | MsgNum/s |
---|---|---|---|---|---|---|
1 | 1048576 | 1 | 1 | 1 | 116.76 | 178222 |
4 | 1048576 | 1 | 1 | 1 | 158.10 | 241312 |
7 | 1048576 | 1 | 1 | 1 | 150.20 | 229252 |
10 | 1048576 | 1 | 1 | 1 | 143.58 | 219154 |
-
测试结论
在threads为4时,消费速度最好达到24.1w/s,而后续慢慢平稳。
4.2.2 fetch-size
- 测试脚本
./bin/kafka-consumer-perf-test.sh --zookeeper 110.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic s1 --messages 1000000 --fetch-size 1000 --threads 3 --hide-header
./bin/kafka-consumer-perf-test.sh --zookeeper 110.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka--topic s1 --messages 1000000 --fetch-size 2000 --threads 3 --hide-header
./bin/kafka-consumer-perf-test.sh --zookeeper 110.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic s1 --messages 1000000 --fetch-size 5000 --threads 3 --hide-header
./bin/kafka-consumer-perf-test.sh --zookeeper 110.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic s1 --messages 1000000 --fetch-size 10000 --threads 3 --hide-header
./bin/kafka-consumer-perf-test.sh --zookeeper 110.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic s1 --messages 1000000 --fetch-size 15000 --threads 3 --hide-header
./bin/kafka-consumer-perf-test.sh --zookeeper 110.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic s1 --messages 1000000 --fetch-size 20000 --threads 3 --hide-header
- 测试结果
Threads | fetch-size | partition | replication | fetch-threads | MB/S | MsgNum/s |
---|---|---|---|---|---|---|
1 | 524288 | 1 | 1 | 1 | 114.86 | 175318 |
1 | 1048576 | 1 | 1 | 1 | 116.59 | 177955 |
1 | 2097152 | 1 | 1 | 1 | 118.88 | 181451 |
1 | 3145728 | 1 | 1 | 1 | 118.87 | 181432 |
1 | 4194304 | 1 | 1 | 1 | 121.37 | 185253 |
1 | 5242880 | 1 | 1 | 1 | 113.46 | 173178 |
-
测试结论
抓取的大小在我们处理687byte的消息时,在419.4w时,性能达到最优121.37m/s;而后续在随着抓取大小的变大而产生性能损耗。
4.2.3 partition
- 测试脚本
1、创建topic
/bin/kafka-topics.sh --create --zookeeper 110.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_kafka_part3 --partitions 3 --replication-factor 1
/bin/kafka-topics.sh --create --zookeeper 110.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_kafka_part5 --partitions 5 --replication-factor 1
/bin/kafka-topics.sh --create --zookeeper 110.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_kafka_part7 --partitions 7 --replication-factor 1
/bin/kafka-topics.sh --create --zookeeper 110.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_kafka_part7 --partitions 9 --replication-factor 1
2、生成数据
/bin/kafka-producer-perf-test.sh --topic test_kafka_perf1 --num-records 10000000 --record-size 687 --producer-props bootstrap.servers=10.240.1.134:9092,10.240.1.143:9092,10.240.1.146:9092 batch.size=1000000 acks=1 compression.type=lz4 --throughput 500000
3、消费数据
./kafka-consumer-perf-test.sh --broker-list localhost:9092 --zookeeper 110.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_kafka_part --messages 10000000 --fetch-size 10240 --threads 5 --hide-header --num-fetch-threads 1
4、初步结论
分区数越多,单线程消费者吞吐率越小。随着更多的broker线程和磁盘开始扫描不同的分区,吞吐量开始显著增加。但是,一旦使用了所有broker线程和磁盘,添加额外的分区没有任何效果。
- 测试结果
Threads | fetch-size | partition | replication | fetch-threads | MB/S | MsgNum/s |
---|---|---|---|---|---|---|
1 | 4194304 | 1 | 1 | 1 | 129.3558 | 197437 |
1 | 4194304 | 3 | 1 | 1 | 203.19 | 310144 |
1 | 4194304 | 5 | 1 | 1 | 214.46 | 327342 |
1 | 4194304 | 7 | 1 | 1 | 121.37 | 185253 |
1 | 4194304 | 9 | 1 | 1 | 121.37 | 185253 |
-
测试结论
分区数在kafka中和处理的线程数有一定的关系,当thread小于partition数时,那么可能存在一个thread消费两个partition,而==两者一样或者说thread大于partition时,实际是一一对应关系==。
4.2.4 replication
- 测试脚本
1、创建topic
/bin/kafka-topics.sh--create --zookeeper 10.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_kafka_rep2 --partitions 5 --replication-factor 2
/bin/kafka-topics.sh--create --zookeeper 10.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_kafka_rep3 --partitions 5 --replication-factor 3
/bin/kafka-topics.sh--create --zookeeper 10.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_kafka_rep4 --partitions 5 --replication-factor 4
/bin/kafka-topics.sh--create --zookeeper 10.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_kafka_rep5 --partitions 5 --replication-factor 5
2、生成数据
/bin/kafka-producer-perf-test.sh --zookeeper 10.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topics test_kafka_rep --messages 10000000 --message-size 4096 --batch-size 10000 --threads 1 --compression-codec 3 --hide-header
3、消费数据
./bin/kafka-consumer-perf-test.sh --zookeeper 10.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_kafka_rep --messages 10000000 --fetch-size 1048576 --threads 5
--num-fetch-threads 1
4、初步结论
备份数越多,吞吐率越低。
- 测试结果
Threads | fetch-size | partition | replication | fetch-threads | MB/S | MsgNum/s |
---|---|---|---|---|---|---|
1 | 4194304 | 1 | 1 | 1 | 129.36 | 197437 |
1 | 4194304 | 1 | 2 | 1 | 103.11 | 157372 |
1 | 4194304 | 1 | 3 | 1 | 67.4 | 102869 |
- 测试结论
数量过少会影响数据的可用性,太多则会白白浪费存储资源,一般建议在2~4为宜,我们设置为3个,既能保障数据的高可用,又避免了浪费过多的存储资源。
4.2.5 fetch-threads
- 测试脚本:
./kafka-consumer-perf-test.sh --zookeeper 10.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_perf --fetch-size 1048576 --messages 1000000 --threads 5 --num-fetch-threads 1
./kafka-consumer-perf-test.sh --zookeeper 10.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_perf --fetch-size 1048576 --messages 10000000 --threads 5 --num-fetch-threads 3
./kafka-consumer-perf-test.sh --zookeeper 10.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_perf --fetch-size 1048576 --messages 50000000 --threads 5 --num-fetch-threads 5
./kafka-consumer-perf-test.sh --zookeeper 10.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_perf --fetch-size 1048576 --messages 100000000 --threads 5 --num-fetch-threads 7
./kafka-consumer-perf-test.sh --zookeeper 10.240.0.9:2181,10.240.0.10:2181,10.240.0.13:2181/kafka --topic test_perf --fetch-size 1048576 --messages 100000000 --threads 5 --num-fetch-threads 10
- 测试结果
Threads|fetch-size|partition|replication|fetch-threads|MB/S|MsgNum/s
--|--|--|--|--|--|--|--
1|4194304| 1 | 1 | 1 | 117.86 | 179881
1|4194304| 1 | 1 | 3 | 137.56 | 209973
1|4194304| 1 | 1 | 6 | 127.63| 194810
1|4194304| 1 | 1 | 7 | 126.73 | 193434
1|4194304| 1 | 1 | 10 | 146.40 | 223458
- 测试结论
在我们控制其他条件不变的情况下,我们更改fetch-thread的线程数,可以发现是随着线程数增多而消费速度加快,在fetch-threads=10时,最优为146.4m/s。