← Dashboard

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.

updated Nov 2026·a 10-minute read·worked numbers, runnable script

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.

Worked example: 20 sorted response times (ms)
StatisticHow it is foundResult
Values110, 115, 120, 120, 125, 130, 130, 135, 140, 145, 150, 155, 160, 170, 185, 210, 260, 480, 1350, 4200
MeanSum of all 20 divided by 20429.5 ms
Median (p50)10th value (nearest rank)145 ms
p9018th value480 ms
p9519th value1,350 ms
p9920th value, which is just the maximum4,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.

Load test types and the question each one answers
TypeQuestion it answersShape
SmokeDoes the script work, and does the system cope with almost no load?One or a few users, short
Average-loadDoes it meet its targets on a normal day?Ramp up, hold at typical traffic, ramp down
StressHow does it behave above normal traffic?Hold at, then beyond, the expected peak
SoakDoes it stay healthy for hours? Memory leaks and exhausted connections show up here.Normal load, held for a long time
SpikeDoes it survive a sudden surge, and recover?Near-vertical ramp, short hold, drop
BreakpointWhere 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.

Worked example: the same target under two models
ScenarioClosed model: 40 virtual usersOpen model: 50 arrivals per second
Iteration takes 0.8 s40 / 0.8 = 50 iterations per second50 per second, about 40 in flight
System slows; iteration takes 4 s40 / 4 = 10 iterations per secondStill 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.

load-test.jsrun: k6 run load-test.js
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.

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.

Open-source load tools, checked October 2026
ToolYou write tests inLicenseNotes
k6JavaScript, run by a Go engineAGPL-3.0Script files live in version control; thresholds built in
Apache JMeterA GUI that saves test plans; runs as a Java applicationApache-2.0Started with web applications and has expanded to other test functions; run from the command line for real load
GatlingJava, JavaScript, TypeScript, Kotlin or ScalaApache-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.

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.

TIPWrite the target before the test. "p95 under 500 ms at 50 requests per second, error rate under 1%" is a requirement. "See how fast it is" is not, and it makes any result look acceptable.

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.

Keep going

Performance connects to automation and monitoring.