京寵展信息指南
810
2022-05-30
前言
安裝插件
新建工程
運(yùn)行結(jié)果
總結(jié)
前言
安裝插件
新建工程
運(yùn)行結(jié)果
總結(jié)
前言
編寫(xiě) Gatling 腳本需要搭建腳本開(kāi)發(fā)環(huán)境,下面演示使用 IDEA 開(kāi)發(fā)環(huán)境搭建腳本開(kāi)發(fā)環(huán)境。
安裝插件
打開(kāi) IDEA,安裝 scala 插件,首次使用,隨便創(chuàng)建一個(gè)工程,進(jìn)入idea頁(yè)面,按:Flie >Settings> Plugins,搜索 Scala,點(diǎn)擊“install”即可,install 為灰色即為已安裝,install 為綠色即為安裝可用(未安裝)狀態(tài),安裝之后,restart 一下 IDEA 即可。
新建工程
創(chuàng)建新工程 Create New Project
選擇 maven,Create form archetype,Add Archetype
輸入內(nèi)容
輸入內(nèi)容:
GroupId : io.gatling.highcharts ArtifactId : gatling-highcharts-maven-archetype Version : 填入你想使用的版本號(hào)
查找版本號(hào)如:
之后的步驟就下一步下一步就行了。
工程目錄如下:
注意:中間 dunsanTest02 是自己寫(xiě)的
目錄結(jié)構(gòu)說(shuō)明:
data:存放需要輸入的數(shù)據(jù) scala:存放你編寫(xiě)的測(cè)試腳本 Engine:右鍵運(yùn)行跟運(yùn)行 Recorder:右鍵運(yùn)行會(huì)彈出錄制程序(不建議使用,建議手動(dòng)開(kāi)發(fā)腳本) target:運(yùn)行測(cè)試之后,測(cè)試報(bào)告存放在此
參考 Demo 代碼:
import io.gatling.core.scenario.Simulation import io.gatling.core.Predef._ import io.gatling.http.Predef._ /** * @author 7d * @Date: 2021-04-27 20:08 * @Description: 簡(jiǎn)單例子 * @version 1.0 */ class dunsanTest02 extends Simulation { object HomeIndex { val home = exec(http("home_index") //設(shè)置請(qǐng)求名稱,可隨意定義 .get("http://localhost:8080/") //請(qǐng)求資源路徑 .check(status.is(200)) //判斷http status ) } // scenario里的參數(shù):scenario name //exec()里的參數(shù)就是我們的執(zhí)行動(dòng)作,http("本次請(qǐng)求的名稱").get("本次http get請(qǐng)求的地址") val page = scenario("性能測(cè)試。").exec(HomeIndex.home) setUp( //設(shè)置線程數(shù) 運(yùn)行10秒 during 默認(rèn)單位秒,如果要用微秒 during(10 millisecond) page.inject(constantUsersPerSec(2) during (10)) // constantUsersPerSec 立馬啟動(dòng)的用戶數(shù),可以理解為并發(fā)數(shù) ) } //repeat(times,counterName) // times:循環(huán)次數(shù) // counterName:計(jì)數(shù)器名稱,可選參數(shù),可以用來(lái)當(dāng)當(dāng)前循環(huán)下標(biāo)值使用,從0開(kāi)始 val scn = scenario("BaiduSimulation").repeat(100){ exec(http("baidu_home").get("/")) } //during(duration, counterName, exitASAP) // duration:時(shí)長(zhǎng),默認(rèn)單位秒,可以加單位milliseconds,表示毫秒 // counterName:計(jì)數(shù)器名稱,可選。很少使用 // exitASAP:默認(rèn)為true,簡(jiǎn)單的可以認(rèn)為當(dāng)這個(gè)為false的時(shí)候循環(huán)直接跳出,可在循環(huán)中進(jìn)行控制是否繼續(xù) /* 運(yùn)行100秒 during 默認(rèn)單位秒,如果要用微秒 during(100 millisecond) */ val scn = scenario("BaiduSimulation").during(100){ exec(http("baidu_home").get("/")) }
運(yùn)行結(jié)果
run 起來(lái)看看:
控制臺(tái)顯示:
運(yùn)行結(jié)果如下:
打開(kāi) html 報(bào)告:
驗(yàn)證寫(xiě)的腳本是否可以放入 gatling 項(xiàng)目運(yùn)行,效果如下:
liwen@ bin % ./gatling.sh GATLING_HOME is set to /Users/liwen/Downloads/gatling-charts-highcharts-bundle-3.5.1 Choose a simulation number: [0] computerdatabase.BasicSimulation [1] computerdatabase.advanced.AdvancedSimulationStep01 [2] computerdatabase.advanced.AdvancedSimulationStep02 [3] computerdatabase.advanced.AdvancedSimulationStep03 [4] computerdatabase.advanced.AdvancedSimulationStep04 [5] computerdatabase.advanced.AdvancedSimulationStep05 [6] dunsanTest02 6 Select run description (optional) tiaoshibiadu Simulation dunsanTest02 started... ================================================================================ 2021-04-27 18:58:28 0s elapsed ---- Requests ------------------------------------------------------------------ > Global (OK=2 KO=0 ) > home_index (OK=2 KO=0 ) ---- 性能測(cè)試。--------------------------------------------------------------------- [##########################################################################]100% waiting: 0 / active: 0 / done: 2 ================================================================================ Simulation dunsanTest02 completed in 0 seconds Parsing log file(s)... Parsing log file(s) done Generating reports... ================================================================================ ---- Global Information -------------------------------------------------------- > request count 2 (OK=2 KO=0 ) > min response time 379 (OK=379 KO=- ) > max response time 506 (OK=506 KO=- ) > mean response time 443 (OK=443 KO=- ) > std deviation 64 (OK=64 KO=- ) > response time 50th percentile 443 (OK=443 KO=- ) > response time 75th percentile 474 (OK=474 KO=- ) > response time 95th percentile 500 (OK=500 KO=- ) > response time 99th percentile 505 (OK=505 KO=- ) > mean requests/sec 2 (OK=2 KO=- ) ---- Response Time Distribution ------------------------------------------------ > t < 800 ms 2 (100%) > 800 ms < t < 1200 ms 0 ( 0%) > t > 1200 ms 0 ( 0%) > failed 0 ( 0%) ================================================================================ Reports generated in 0s. Please open the following file: /Users/liwen/Downloads/gatling-charts-highcharts-bundle-3.5.1/results/dunsantest02-20210427105826635/index.html
總結(jié)
大家觀察出來(lái),Gatling 在運(yùn)行的時(shí)候不像 JMeter 一樣,在運(yùn)行的時(shí)候輸入時(shí)間與加載方式,Gatling 控制都在腳本中編寫(xiě)。
更多操作請(qǐng)參考官方文檔:https://gatling.io/docs/current/
相關(guān)系列:
性能工具之 Gatling 快速入門(mén)
性能工具之 Gatling 開(kāi)發(fā)環(huán)境搭建
IDE 壓力測(cè)試
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請(qǐng)聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。