我想通過不斷增加負載來運行壓力測驗,直到回應時間變得不可接受。我需要檢查的條件是所有請求的 95% 花費的時間不超過 1 秒。
- 我可以在運行時動態確定這一點嗎?如果是,如何確定?
- 達到此條件后如何停止測驗?
我查看了 AutoStop Listener 插件,但它似乎沒有檢查此條件所需的內容。
uj5u.com熱心網友回復:
最簡單的是
- 初始化屬性。添加一個設定執行緒組。將JSR223 采樣器添加到設定執行緒組。然后添加以下代碼來初始化屬性。
props.put("total_requests","0")
props.put("total_requests_exceeding_limit","0")
- 在頂層添加JSR223 后處理器。
這將確保該元素應用于測驗計劃中的所有采樣器
- 將以下引數添加到 JSR223 Post Processor
${__P(stop_test_exceeding_percentile_error,true)} ${__P(percentage_limit,95)} ${__P(response_time_limit_in_seconds,1)}
- 將以下腳本添加到 JSR223 后處理器。
long rampupTime=60000
long requestCountToStartChecking=50
long startTimeInMillis=vars.get("TESTSTART.MS").toLong()
long currentTimeInMillis = new Date().getTime()
long currentTestDurationInMillis=currentTimeInMillis-startTimeInMillis
log.info("currentTestDurationInMillis ${currentTestDurationInMillis}")
if(args[0].toBoolean() && currentTestDurationInMillis> rampupTime ){
def total_requests_exceeding_limit
def percentageOfRequestExceedingLimit
int percentile_limit=args[1].toInteger()
int response_time_limit_in_seconds=args[2].toInteger()
long response_time_limit_in_milliseconds=response_time_limit_in_seconds*1000
def totalRequests = props.get("total_requests").toInteger() 1
props.put("total_requests",totalRequests.toString())
if(prev.getTime() > response_time_limit_in_milliseconds && totalRequests> requestCountToStartChecking){
total_requests_exceeding_limit= props.get("total_requests_exceeding_limit").toInteger() 1
percentageOfRequestExceedingLimit = (total_requests_exceeding_limit/totalRequests)* 100
if (percentageOfRequestExceedingLimit> percentile_limit) {
log.info("Requests execeeding ${response_time_limit_in_milliseconds} has reached ${percentageOfRequestExceedingLimit}")
log.info("Stopping the test")
prev.setStopTest(true)
}
props.put("total_requests_exceeding_limit",total_requests_exceeding_limit.toString())
}
log.info("totalRequests ${totalRequests} total_requests_exceeding_limit ${total_requests_exceeding_limit} percentageOfRequestExceedingLimit ${percentageOfRequestExceedingLimit} ")
}
- 腳本將在加速期間忽略采樣器。
- 可以通過屬性配置回應時間閾值、回應百分比限制等
- 百分比將在啟動時間達到預定義數量的請求后進行檢查,以避免在第一次回應時間大于配置值時立即停止測驗。
Sample Test Plan is uploaded to GitHub
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/323496.html
標籤:表现 电表 听众 jmeter-5.0 压力测试
下一篇:為什么我的合并排序實作很慢?
