qa / performance testing
Performance Testing: Percentiles, Load Profiles and a First k6 Script
How to read a response-time result without being fooled by the average, how to choose between a smoke, load, stress, spike and soak test, and how to turn those choices into a k6 script that fails the build when the system is too slow. Tool facts were checked on the k6, JMeter and Gatling sites in October 2026.
A load test produces thousands of numbers, and the first mistake almost everyone makes is summarizing them with one: the average. A system can have a perfectly respectable average response time while one user in twenty waits several seconds. The second mistake is testing the wrong shape of traffic, such as ramping to a flat plateau when the real risk is a sudden spike from a marketing email. This guide starts with the arithmetic that exposes the first mistake, then walks through the choice that prevents the second, and ends with a script you can run against a staging server you own.
01 · READING THE RESULT
Why the average hides your slowest users
Take twenty response times from a short test, in milliseconds, sorted from fastest to slowest. Nineteen requests look healthy. The last two are not.
| Statistic | How it is found | Result |
|---|---|---|
| Values | 110, 115, 120, 120, 125, 130, 130, 135, 140, 145, 150, 155, 160, 170, 185, 210, 260, 480, 1350, 4200 | |
| Mean | Sum of all 20 divided by 20 | 429.5 ms |
| Median (p50) | 10th value (nearest rank) | 145 ms |
| p90 | 18th value | 480 ms |
| p95 | 19th value | 1,350 ms |
| p99 | 20th value, which is just the maximum | 4,200 ms |
The mean is 430 ms, a number that describes none of these requests: fifteen finished in under 200 ms and two took more than a second. The median says "typical user, fine", and p95 says "one in twenty users waits over a second". If your service level objective is "95% of requests under 500 ms", this run fails, and the average would never have told you. Two cautions apply. With 20 samples, p99 is only the slowest request, so you need at least a hundred samples before p99 means anything. And tools differ in method: some interpolate between neighboring samples, and linear interpolation on this same data reads p95 as about 1,493 ms, not 1,350.
Google's Site Reliability Engineering book makes the same point with a service averaging 100 ms at 1,000 requests per second, where 1% of requests might easily take five seconds. It also notes that a high-percentile latency measured over a short window is an early signal that a system is saturating.
02 · THE PROFILE QUESTION
Choosing a load profile
A "performance test" is really six different tests that answer different questions. k6's documentation lists them, and the useful habit is to state the question before choosing the shape.
| Type | Question it answers | Shape |
|---|---|---|
| Smoke | Does the script work, and does the system cope with almost no load? | One or a few users, short |
| Average-load | Does it meet its targets on a normal day? | Ramp up, hold at typical traffic, ramp down |
| Stress | How does it behave above normal traffic? | Hold at, then beyond, the expected peak |
| Soak | Does it stay healthy for hours? Memory leaks and exhausted connections show up here. | Normal load, held for a long time |
| Spike | Does it survive a sudden surge, and recover? | Near-vertical ramp, short hold, drop |
| Breakpoint | Where is the capacity limit? | Load that keeps rising until something breaks |
k6's advice is to start with a smoke test, then progress to higher loads and longer durations. In practice that means you do not schedule a four-hour soak test until a two-minute smoke test has proved the script is correct. Otherwise you learn at hour three that every request was returning a 401.
03 · OPEN OR CLOSED
How many virtual users is 50 requests a second?
Stakeholders speak in requests per second; most tools default to a count of virtual users. Little's law converts between them: concurrent users equals arrival rate times time spent in the system. If 50 iterations start each second and each takes 0.8 seconds, about 40 are in flight at any moment.
| Scenario | Closed model: 40 virtual users | Open model: 50 arrivals per second |
|---|---|---|
| Iteration takes 0.8 s | 40 / 0.8 = 50 iterations per second | 50 per second, about 40 in flight |
| System slows; iteration takes 4 s | 40 / 4 = 10 iterations per second | Still 50 per second, so about 200 in flight |
In a closed model, a new iteration starts only when the last one finishes, so a struggling system quietly receives less traffic and looks better than it is. k6's documentation describes exactly this tapering and notes that some testing literature calls the problem coordinated omission. An open model, which k6 provides through its arrival-rate executors, keeps sending at the planned rate. Gatling draws the same open and closed distinction in its injection profiles. Use an open model when you are modeling independent visitors, and a closed model when you are modeling a fixed pool of users, such as a call center.
04 · THE SCRIPT
A k6 test that fails when p95 is too slow
This script holds 50 arrivals per second for five minutes and encodes a pass/fail rule. The thresholds are the important part: a run that exits with a failure turns a load test from a chart someone must interpret into a check a pipeline can enforce. Point it only at a system you own or have written permission to test.
import http from 'k6/http'; import { check } from 'k6'; export const options = { scenarios: { steady: { executor: 'constant-arrival-rate', rate: 50, // iterations started... timeUnit: '1s', // ...per second duration: '5m', preAllocatedVUs: 60, // Little's law said ~40; leave headroom maxVUs: 200, }, }, thresholds: { http_req_failed: ['rate<0.01'], // under 1% errors http_req_duration: ['p(95)<500', 'p(99)<1500'], // tail latency }, }; export default function () { const res = http.get('https://staging.example.com/api/products'); check(res, { 'status is 200': (r) => r.status === 200 }); }
The executor name, the required preAllocatedVUs parameter and the threshold syntax come from the k6 documentation. The executor page describes this as the choice for keeping the rate constant regardless of how the system under test performs. Treat any shortfall against the planned rate as a finding in itself, since it means the load generator or the system hit a limit. Apply the percentile lesson from section one: five minutes at 50 per second produces about 15,000 samples, enough for p99 to be meaningful.
- k6: Thresholds ↗The pass/fail syntax, including percentile expressions and aborting a test early when a threshold is breached.grafana.com
- k6: Constant arrival rate executor ↗The options for the executor used above: rate, timeUnit, preAllocatedVUs and maxVUs.grafana.com
- k6: Install ↗Packages for Linux, macOS and Windows (winget, Chocolatey, Homebrew), plus a Docker image.grafana.com
05 · THE TOOLS
k6, JMeter or Gatling
All three are free to use and can do the job. They differ in how you write a test, and that decides which one you will actually maintain.
| Tool | You write tests in | License | Notes |
|---|---|---|---|
| k6 | JavaScript, run by a Go engine | AGPL-3.0 | Script files live in version control; thresholds built in |
| Apache JMeter | A GUI that saves test plans; runs as a Java application | Apache-2.0 | Started with web applications and has expanded to other test functions; run from the command line for real load |
| Gatling | Java, JavaScript, TypeScript, Kotlin or Scala | Apache-2.0 (open-source repository) | Enterprise Edition is a separate, paid product |
If you want tests that read like code and review like code, start with k6. If your team already has JMeter test plans or needs a protocol k6 lacks, JMeter's manual includes a best-practices page. One rule from it is worth memorizing: build and debug the plan in the GUI, then run the actual load from the command line and keep the number of listeners low, because result viewers consume resources that the test needs.
- JMeter: Best practices ↗Use CLI mode for load runs, disable heavy listeners such as View Results Tree during the test, and other ways to reduce the tool's own resource use.jmeter.apache.org
- Apache JMeter ↗Downloads, the user manual and component reference for the 100% Java load-testing application.jmeter.apache.org
- Gatling documentation ↗Getting-started guides for the Java and JavaScript SDKs, with Community and Enterprise edition release notes.docs.gatling.io
06 · WHAT SPOILS A RESULT
Five ways to produce a meaningless number
Most bad results come from the test setup, not the system.
Testing production without a plan. A stress or breakpoint test is meant to break things. Run it against a staging environment with production-like data and hardware, or accept the outage you are creating.
Letting the load generator be the bottleneck. If the machine running the test is at full CPU, you are measuring it. Watch its CPU and network while the test runs.
Reporting the mean. Covered above. Report p50, p95 and p99 together, along with the error rate.
Ignoring warm-up. The first minute often includes cold caches and connection setup. Ramp up slowly and judge the steady-state window.
Hitting one URL. Real traffic mixes endpoints and users. A test that requests the cached home page 50 times a second says little about checkout.
07 · FAQ
Frequently asked questions
What is performance testing?
Performance testing measures how a system behaves under load: response time, throughput, error rate and resource use. It covers several types, including smoke, load, stress, spike, soak and breakpoint tests, each answering a different question about capacity and stability.
What is the difference between load and stress testing?
A load test checks that the system meets its targets at expected traffic. A stress test pushes beyond the expected peak to see how it degrades and whether it recovers. A breakpoint test keeps raising load until the system fails, to find its limit.
Which performance testing tool should I learn first?
k6 is the quickest to start if you can read JavaScript, because tests are plain script files with built-in pass/fail thresholds. JMeter suits teams that prefer a GUI or need its protocol support, and Gatling suits JVM teams. All three are free to use.
Why should I use percentiles instead of averages?
An average blends fast and slow requests into a number that matches neither. In the 20-sample example above the mean is about 430 ms while p95 is 1,350 ms. Percentiles show what the slowest users actually experience.
Do I need to know how to code for performance testing?
Basic scripting helps a great deal. k6 and Gatling tests are code, and even JMeter needs logic for correlating tokens and parameterizing data. You do not need to be a developer, but you should be comfortable reading and editing short scripts.