jmeter取樣器之KafkaProducerSampler(往kafka插入數(shù)據(jù))
項(xiàng)目背景
性能測(cè)試場(chǎng)景中有一個(gè)業(yè)務(wù)場(chǎng)景的數(shù)據(jù)抽取策略是直接使用kafka隊(duì)列,該場(chǎng)景需要準(zhǔn)備的測(cè)試數(shù)據(jù)是kafka隊(duì)列里的數(shù)據(jù),故需要實(shí)現(xiàn)插入數(shù)據(jù)到kafka隊(duì)列,且需要實(shí)現(xiàn)控制每分鐘插入多少條數(shù)據(jù)。
解決方案
通過研究了解到j(luò)meter工具的kafka插件可以實(shí)現(xiàn)往kafka插入數(shù)據(jù),且可以通過jmeter的固定吞吐量控制器實(shí)現(xiàn)每分鐘插入多少條數(shù)據(jù)。
1、jmeter中下載kafka插件
jmeter界面,菜單Options>Plugins Manager,在Available頁(yè)簽中搜索kafka安裝DI KafkaMeter和Kafka Support,由于本次已安裝所以這里是顯示在Installed Plugins頁(yè)簽里面。


2、添加配置元件KafkaProducerConfig

Kafka Brokers配置kafka的IP和端口,其他保持默認(rèn)配置,無需改動(dòng)。

3、添加取樣器KafkaProducerSampler

配置KafkaProducerSampler,配置kafka topic和message

4、執(zhí)行腳本,實(shí)現(xiàn)往kafka插入數(shù)據(jù)。

5、添加固定吞吐量控制器,實(shí)現(xiàn)每分鐘插入的條數(shù)。
在kafka取樣器請(qǐng)求下添加固定吞吐量控制器,操作步驟:Add>Timer>Constant Throughput Timer
Constant Throughput Timer控制器中Target throughput(in samples per minute)設(shè)置每分鐘需要插入的條數(shù),如此處的360則代表每分鐘插入360條數(shù)據(jù)。
Calculate Throughput based on選擇all active threads in current thread group

應(yīng)用價(jià)值
jmeter的配置元件KafkaProducerConfig和KafkaProducerSampler可以實(shí)現(xiàn)往kafka隊(duì)列寫數(shù)據(jù);jmeter的吞吐量控制器Constant Throughput Timer可實(shí)現(xiàn)每分鐘插入多少數(shù)據(jù)。
posted on 2022-06-17 10:13 seamy 閱讀(2720) 評(píng)論(2) 收藏 舉報(bào)
浙公網(wǎng)安備 33010602011771號(hào)