教育行業(yè)A股IPO第一股(股票代碼 003032)

全國咨詢/投訴熱線:400-618-4000

Kafka基準測試怎樣進行?

更新時間:2021年09月29日09時35分 來源:傳智教育 瀏覽次數(shù):

好口碑IT培訓

基準測試(benchmark testing)是一種測量和評估軟件性能指標的活動。我們可以通過基準測試,了解到軟件、硬件的性能水平。主要測試負載的執(zhí)行時間、傳輸速度、吞吐量、資源占用率等。

1)基于1個分區(qū)1個副本的基準測試:
1. 啟動Kafka集群
2. 創(chuàng)建一個1個分區(qū)1個副本的topic: benchmark
3. 同時運行生產(chǎn)者、消費者基準測試程序
4. 觀察結(jié)果

創(chuàng)建topic

bin/kafka-topics.sh --zookeeper node1.itcast.cn:2181 --create --topic benchmark --partitions 1 --replication-factor 1

2)生產(chǎn)消息基準測試

在生產(chǎn)環(huán)境中,推薦使用生產(chǎn)5000W消息,這樣會性能數(shù)據(jù)會更準確些。為了方便測試,課程上演示測試500W的消息作為基準測試。

bin/kafka-producer-perf-test.sh --topic benchmark --num-records 5000000 
--throughput -1 --record-size 1000 --producer-props 
bootstrap.servers=node1.itcast.cn:9092,node2.itcast.cn:9092,node3.itcast.cn:9092 
acks=1
bin/kafka-producer-perf-test.sh  
--topic  topic的名字
--num-records 總共指定生產(chǎn)數(shù)據(jù)量(默認5000W)
--throughput 指定吞吐量——限流(-1不指定)
--record-size    record數(shù)據(jù)大?。ㄗ止?jié))
--producer-props  bootstrap.servers=192.168.1.20:9092,192.168.1.21:9092,192.168.1.22:9092 acks=1  指定Kafka集群地址,ACK模式

測試結(jié)果:

1632825924313_基準測試.png

3)消費消息基準測試

bin/kafka-consumer-perf-test.sh --broker-list 
node1.itcast.cn:9092,node2.itcast.cn:9092,node3.itcast.cn:9092 --topic benchmark 
--fetch-size 1048576 --messages 5000000
bin/kafka-consumer-perf-test.sh
--broker-list 指定kafka集群地址
--topic 
指定topic的名稱
--fetch-size 每次拉取的數(shù)據(jù)大小
--messages 總共要消費的消息個數(shù)

1632825930851_12.png


4)基于3個分區(qū)1個副本的基準測試
被測虛擬機:

1632825938283_13.png
創(chuàng)建topic

bin/kafka-topics.sh --zookeeper node1.itcast.cn:2181 --create --topic benchmark
 --partitions 3 --replication-factor 1

5)生產(chǎn)消息基準測試

bin/kafka-producer-perf-test.sh --topic benchmark --num-records 5000000 
--throughput -1 --record-size 1000 --producer-props 
bootstrap.servers=node1.itcast.cn:9092,node2.itcast.cn:9092,node3.itcast.cn:9092 
acks=1bin/kafka-consumer-perf-test.sh

測試結(jié)果:
1632825951863_14.png
1632825958811_14.5.png

還是一樣,因為虛擬機的原因,多個分區(qū)反而消費的效率也有所下降。

基于1個分區(qū)3個副本的基準測試

創(chuàng)建topic

bin/kafka-topics.sh --zookeeper node1.itcast.cn:2181 --create --topic benchmark --partitions 
1 --replication-factor 3

6)生產(chǎn)消息基準測試

bin/kafka-producer-perf-test.sh --topic benchmark --num-records 5000000 
--throughput -1 --record-size 1000 --producer-props 
bootstrap.servers=node1.itcast.cn:9092,node2.itcast.cn:9092,node3.itcast.cn:9092 
acks=1

測試結(jié)果:

1632825968850_15.png

同樣的配置,副本越多速度越慢。

7)消費消息基準測試

bin/kafka-consumer-perf-test.sh --broker-list 
node1.itcast.cn:9092,node2.itcast.cn:9092,node3.itcast.cn:9092 --topic benchmark 
--fetch-size 1048576 --messages 5000000

1632825975097_16.png




猜你喜歡:

Django如何給客戶端推送消息?App推送怎樣實現(xiàn)?

MySQL數(shù)據(jù)庫怎樣分區(qū)和分表?【數(shù)據(jù)分析面試題】

ZooKeeper在集群Master選舉中應用介紹

Zookeeper分布式系統(tǒng)的集群架構(gòu)介紹

傳智教育python大數(shù)據(jù)開發(fā)培訓

0 分享到:
和我們在線交談!