Skip to content
Go back

Thresholds in k6 - The Guardrails of Performance Testing

Edit page

When you test a SaaS dashboard—or any web service—you’re not just measuring numbers. You’re defining boundaries. These boundaries are called thresholds, and they describe what “good enough” means for your system under load. In k6, these boundaries are called thresholds, and they act like automatic pass/fail checks for your test script.

Thresholds answer questions like:

Before setting thresholds, you need to understand the fundamentals: what latency means, what percentiles represent, and why units matter.

In this post, we’ll walk through thresholds step by step using your JWT SaaS dashboard API from earlier posts.

Table of contents

Open Table of contents

What Latency Actually Measures

Latency is the time it takes for a request to travel through your system and return a response. In k6, it includes:

In k6 you’ll see numbers like:

http_req_duration: 0.233

That means 0.233 seconds, which is 233 ms.

Percentiles: Why They Matter

Some requests will always be slower due to network hiccups, server load, or cache misses.Actual response to Real-world users will always be in flux.

Percentiles show how your system behaves for most users:

Example:

If p99 = 900 ms, then 99% of your requests completed under 900 ms. That upper tail is meaningful because even small tail latencies can break user flows in dashboards:

Error Rate and Its Thresholds

Error thresholds define what failure level is acceptable.

Typical categories:

Example threshold:

http_req_failed: ["rate<0.01"]

Meaning: < 1% of all requests may fail during the entire test.

Throughput and Why It Gets a Threshold Too

Throughput measures how many requests per second your service can sustain. In SaaS dashboards, throughput tends to spike:

A throughput threshold might look like:

checks: ["rate>100"]

Meaning: The service should handle more than 100 successful operations per second.

Throughput thresholds prevent silent regressions where latency looks fine but capacity quietly drops.

Three Categories of Thresholds (Conceptually)

k6 divides thresholds into conceptual types:

  1. Thresholds That Must Be Fast

These directly impact UX.

Common metrics:

These are strict. If the 95th percentile goes above your defined limit, the test fails.

  1. Thresholds That Can Be Slower

These are more flexible and used to observe trends, not enforce strict rules.

Examples:

They’re still important, but they rarely make the test fail.

  1. Thresholds That Must Never Fail

These represent hard requirements.

Examples:

These act as non-negotiable “gates.”

Putting It All Together

export const options = {
  thresholds: {
    // Latency
    http_req_duration: ["p(95)<500", "p(99)<900"],

    // Error rate
    http_req_failed: ["rate<0.01"],

    // Throughput
    checks: ["rate>100"],
  },
};

What this means,

Exercises (Try It Yourself)


Edit page
Share this post on:

Next Post
Introduction & Getting Started with k6