Skip to main content
Thresholds define the pass/fail criteria for your load tests. If your system doesn’t meet the threshold conditions, the test fails with a non-zero exit code. Thresholds let you codify your Service Level Objectives (SLOs) and automate performance testing.

How thresholds work

Thresholds evaluate metrics against specified conditions. Common examples include:
  • Less than 1% of requests return errors
  • 95% of requests complete within 200ms
  • 99% of requests complete within 400ms
  • Specific endpoints always respond within 300ms
When any threshold fails, k6 exits with a non-zero exit code, making thresholds essential for CI/CD integration.

Basic example

This test defines two thresholds:
When you run this test, k6 displays threshold results:
The green checkmarks (✓) indicate passing thresholds. Failed thresholds show a red cross (✗) and cause the test to exit with code 1.

Threshold syntax

Thresholds use this format:

Threshold expressions

A threshold expression has three parts:
Examples:
  • avg < 200 - Average duration must be less than 200ms
  • count >= 500 - Count must be at least 500
  • p(90) < 300 - 90th percentile must be below 300ms

Aggregation methods by metric type

Different metric types support different aggregation methods:

Common threshold examples

Error rate threshold

Ensure error rate stays below 1%:

Response time threshold

Ensure 90% of requests complete within 400ms:

Multiple thresholds on one metric

Define different requirements for different percentiles:

Thresholds with custom metrics

You can set thresholds on custom metrics:

Thresholds on tagged metrics

Set thresholds for specific tagged requests:

Thresholds on groups

Set thresholds for specific groups:

Abort test when threshold fails

Stop the test immediately when a threshold fails:
The delayAbortEval property prevents premature test abortion by waiting for enough samples to be collected.

Fail test using checks

Combine checks with thresholds to fail tests based on check results:

Thresholds on specific checks

Use tags to set thresholds for specific checks:

Complete example

Here’s a comprehensive example combining multiple threshold patterns:

Best practices

Start with SLOs

Base thresholds on your Service Level Objectives, not arbitrary numbers.

Use multiple percentiles

Don’t rely on averages alone. Check p95, p99, and max values.

Tag for granularity

Use tags to set different thresholds for different request types.

Delay abort evaluation

Use delayAbortEval to prevent premature test abortion.