| title | Load Testing Thresholds |
|---|---|
| page-title | Setting Thresholds for Load Tests |
| description | How to set and control failure thresholds for the load tests |
| meta-description | Learn how to set and control failure thresholds for the load tests |
| order | 60 |
| version | since:com.vaadin:vaadin@V25.2 |
k6 thresholds define pass/fail criteria for your load tests.
When a threshold is breached, k6 marks the test as failed, and the Maven build fails if k6.failOnThreshold=true (the default).
The TestBench k6 converter plugin generates some default thresholds automatically in every k6 script produced. You can configure the default thresholds, disable individual ones, or add custom thresholds for any k6 metric.
Every generated k6 script includes these thresholds out of the box:
| Metric | Expression | Default |
|---|---|---|
|
95th percentile response time |
|
|
99th percentile response time |
|
|
All checks must pass |
|
This generates the following block in the k6 script:
export const options = {
thresholds: {
checks: [{ threshold: 'rate==1', abortOnFail: true, delayAbortEval: '5s' }],
http_req_duration: ['p(95)<2000', 'p(99)<5000'],
},
}You can change the default threshold values with Maven properties or through configuration in the POM.
# Tighter response time requirements
mvn k6:convert -Dk6.harFile=recording.har \
-Dk6.threshold.httpReqDurationP95=1000 \
-Dk6.threshold.httpReqDurationP99=3000
# Allow checks to fail without aborting the test
mvn k6:convert -Dk6.harFile=recording.har \
-Dk6.threshold.checksAbortOnFail=false
# Disable the p95 threshold entirely (set to 0)
mvn k6:convert -Dk6.harFile=recording.har \
-Dk6.threshold.httpReqDurationP95=0<plugin>
<groupId>com.vaadin</groupId>
<artifactId>testbench-converter-plugin</artifactId>
<configuration>
<!-- 95th percentile response time in ms (0 to disable) -->
<httpReqDurationP95>1000</httpReqDurationP95>
<!-- 99th percentile response time in ms (0 to disable) -->
<httpReqDurationP99>3000</httpReqDurationP99>
<!-- Set to false to continue the test even when checks fail -->
<checksAbortOnFail>false</checksAbortOnFail>
</configuration>
</plugin>| Parameter | Default | Description |
|---|---|---|
|
|
95th percentile response time threshold in ms. Set to |
|
|
99th percentile response time threshold in ms. Set to |
|
|
When |
You can add pass/fail thresholds for any k6 built-in metric using the k6.threshold.custom property.
The format is a comma-separated list of metric:expression pairs:
metric1:expression1,metric2:expression2,...# Fail if more than 1% of requests fail
mvn k6:run -Dk6.testFile=test.js \
-Dk6.threshold.custom="http_req_failed:rate<0.01"
# Multiple custom thresholds
mvn k6:run -Dk6.testFile=test.js \
-Dk6.threshold.custom="http_req_failed:rate<0.01,http_req_waiting:p(95)<500,http_reqs:count>100"<plugin>
<groupId>com.vaadin</groupId>
<artifactId>testbench-converter-plugin</artifactId>
<configuration>
<!-- Custom thresholds in metric:expression format -->
<customThresholds>http_req_failed:rate<0.01,http_req_waiting:p(95)<500</customThresholds>
</configuration>
</plugin>|
Note
|
In XML, use < instead of < inside threshold expressions.
|
Custom thresholds are added alongside the defaults.
If you add a custom http_req_duration expression, it is merged with the default p95/p99 thresholds:
# Adds a median threshold alongside the existing p95 and p99
mvn k6:convert -Dk6.harFile=recording.har \
-Dk6.threshold.custom="http_req_duration:p(50)<1000"This produces:
export const options = {
thresholds: {
checks: [{ threshold: 'rate==1', abortOnFail: true, delayAbortEval: '5s' }],
http_req_duration: ['p(95)<2000', 'p(99)<5000', 'p(50)<1000'],
},
}Below are commonly used threshold configurations for Vaadin load tests.
mvn k6:run -Dk6.testFile=test.js \
-Dk6.threshold.httpReqDurationP95=500 \
-Dk6.threshold.httpReqDurationP99=1000 \
-Dk6.threshold.custom="http_req_failed:rate<0.001,http_req_waiting:p(95)<300"Generated output:
thresholds: {
checks: [{ threshold: 'rate==1', abortOnFail: true, delayAbortEval: '5s' }],
http_req_duration: ['p(95)<500', 'p(99)<1000'],
http_req_failed: ['rate<0.001'],
http_req_waiting: ['p(95)<300'],
},mvn k6:run -Dk6.testFile=test.js \
-Dk6.threshold.httpReqDurationP95=10000 \
-Dk6.threshold.httpReqDurationP99=0 \
-Dk6.threshold.checksAbortOnFail=false \
-Dk6.threshold.custom="http_req_failed:rate<0.05"Generated output:
thresholds: {
checks: ['rate==1'],
http_req_duration: ['p(95)<10000'],
http_req_failed: ['rate<0.05'],
},The following k6 built-in metrics can be used with custom thresholds. For the full reference, see the k6 metrics documentation.
| Metric | Type | Description |
|---|---|---|
|
Trend |
Total time for the request (send + wait + receive) |
|
Trend |
Time spent waiting for response (Time to First Byte) |
|
Trend |
Time spent establishing TCP connection |
|
Trend |
Time spent sending data |
|
Trend |
Time spent receiving data |
|
Rate |
Rate of failed requests |
|
Counter |
Total number of requests |
|
Rate |
Rate of successful checks |
Trend metrics support: p(N)<value, avg<value, min<value, max<value, med<value
Rate metrics support: rate<value, rate>value
Counter metrics support: count<value, count>value