Skip to content
Tutorials Center
My learning

Topics

Lesson 42 of 60 ยท Non-functional Testing Concepts

Performance, Load and Stress Testing

Learn response time, throughput and percentiles, and how load, stress, soak and spike tests differ, with runnable simulations that compute p95.

A page can show exactly the right data and still be a failure if it takes twelve seconds to appear. Performance testing asks a different question from the functional tests you have written so far: not "is the answer correct?" but "how fast, and for how many people at once?" Users leave slow sites, checkouts time out during sales, and a system that works for ten testers can collapse under ten thousand customers.

This lesson explains the vocabulary (response time, throughput, percentiles), the main kinds of performance test, and how to think about bottlenecks. Real load generators need a server and a network, so the code here is a stand-in: small simulations that run in your browser and use the same arithmetic real tools use to report their results. Performance is one of the non-functional test types, so it is worth reading that overview first.

What we measure

Three measurements appear in almost every performance report.

  • Response time (or latency): how long one request takes from the moment the user acts until the answer arrives. Measured per request, usually in milliseconds.
  • Throughput: how much work the system finishes per unit of time, for example 250 requests per second or 40 orders per minute.
  • Resource use: CPU, memory, disk and network consumption on the machines doing the work. High response times usually have a resource that is running out behind them.

These are linked. As load grows, throughput rises at first, then flattens when something saturates, and response time begins to climb. The art of performance testing is finding where that bend is.

Three numbers to watch

Response time How long one request takes.
Throughput How many requests finish per second.
Resource use CPU, memory, disk and network.

They move together as load grows.

1 / 2

Why averages lie: percentiles

Suppose 100 requests are measured. Ninety-five finish in 100 ms, and five take 5,000 ms. The average is 345 ms, which describes nobody's real experience: most users saw 100 ms and a few saw five seconds. The average hides the pain.

Testers therefore report percentiles. The 95th percentile (p95) is the response time that 95 percent of requests were at or below. If p95 is 300 ms, then one request in twenty was slower than that. Common choices are:

  • p50 (median): the typical request.
  • p95: the experience of "a bad day" for roughly one user in twenty.
  • p99: the slow tail. At high traffic, 1 percent of requests is a lot of people.

A requirement written as "the average response is under one second" is weak. A better one reads: "p95 of the search request is under 800 ms with 200 concurrent users." It names a percentile, a request and a load, so you can actually test it. This is the same testability thinking from reviewing requirements.

Try it: compute percentiles from simulated requests

This script generates 1,000 fake response times from a seeded random generator (so the output is the same every run): most are fast, a few percent are slow. It then reports the average and several percentiles using the common "nearest rank" method. This stand-in shows the calculation; a real tool such as k6 or JMeter measures real requests.

JS Average versus percentiles

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Look at how the average sits well above the median but far below the p99. In this run only about 3 percent of requests are slow, so p95 still looks healthy while p99 exposes multi-second waits. No single user experiences the average, which is why reports show several numbers together.

The kinds of performance test

All of these use the same idea (send simulated users at the system and measure), but each answers a different question.

Test Question it answers Typical shape
Load test Does the system meet its targets at expected traffic? Ramp to the planned number of users and hold
Stress test Where does it break, and how does it fail? Keep increasing load past the limit
Soak (endurance) test Does it stay healthy for hours or days? Normal load for a long time
Spike test Does it survive a sudden surge and recover? Jump from low to high load in seconds
Scalability test Does adding servers add capacity? Repeat load tests as resources grow

A stress test is about failure behavior as much as the limit itself. Does the system return clear errors and recover when load drops, or does it corrupt data and need a manual restart? A soak test finds slow problems that short tests miss, such as a memory leak that only fills the heap after six hours. Recovery after failure has its own lesson: Reliability, Recovery and Disaster Testing.

flowchart LR
  A["Few users<br/>fast and steady"] --> B["Planned load<br/>meets targets"]
  B --> C["Saturation<br/>response time climbs"]
  C --> D["Breaking point<br/>errors and timeouts"]

Load rises from left to right; load tests live around B, stress tests push through C to D.

Volume, spike, endurance and scalability tests in detail

The table of test kinds above is a summary. These four deserve a closer look, because their set-up and the shape of their graph differ from a plain load test.

Volume testing

Volume testing (flood testing) fills the system with a large amount of data and checks that it still behaves: a database with fifty million rows, a mailbox with a hundred thousand messages, a file import of two gigabytes. The load is not many users but many records.

What to look for: slow queries and missing indexes, screens that load every row at once, import and export time, storage and backup growth, report generation time, and memory use when a single request touches a huge result. Volume bugs hide in lists, search, reports and batch jobs, because they work perfectly with the small data that developers use.

Spike testing

A spike test applies a sudden, extreme increase in users or requests for a short time and then drops back, such as a ticket sale opening or a push notification reaching a million phones.

Questions: Does the system stay up? Do autoscaling and queues react in time? Are errors graceful (a "busy, retry" message) rather than corrupt? Does it recover to normal response times once the spike ends? The graph looks like a narrow tower.

Endurance (soak) testing

An endurance test runs a normal, steady load for a long time (hours or days) to expose slow degradation: memory leaks, connection leaks, growing log files, queues that never drain, cache bloat, certificate or token expiry, and nightly jobs colliding with traffic. Its graph is a long flat plateau, and the interesting part is whether any metric drifts upward. See also Concurrency and Stability Testing.

Scalability testing

A scalability test asks how the system's capacity changes when you add resources, or when load grows. You run the same load test at several sizes (1, 2, 4, 8 servers; 1,000, 2,000, 4,000 users) and chart throughput and response time. Ideal linear scalability doubles throughput when you double servers. Real systems flatten because a shared resource (a database, a lock, a single queue) becomes the bottleneck. Scalability testing finds that limit and tells you whether to scale up (a bigger machine) or out (more machines).

The shapes side by side

Test Varies Watches Typical duration
Load Users up to the expected number Response time, errors against targets 30 minutes to hours
Stress Users beyond capacity Breaking point and failure mode Until it breaks
Spike Users, suddenly Survival and recovery Minutes
Endurance Time Drift in memory, connections, latency 8 hours to days
Volume Data size Query time, storage, batch time Varies
Scalability Resources or user count in steps Throughput per resource added Several runs

The common process

  1. Define goals as numbers (95th percentile under 800 ms, error rate under 1%).
  2. Choose a realistic workload from production analytics: which pages, in what mix.
  3. Prepare a production-like environment and data (see Test Data and Environments).
  4. Script the scenarios and set the load profile.
  5. Run and monitor the application, database and hosts together, and record.
  6. Analyse: compare with the goals, find bottlenecks, change one thing, repeat.
JS Draw four load profiles

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Volume and scalability tests do not have a user curve of their own: volume changes the amount of data, and scalability repeats runs at growing sizes.

Bottlenecks

When a system slows down, one part is usually the limiting resource, the bottleneck. It might be a database query without an index, a single-threaded service, a small connection pool, a slow third-party API, or a network link. Speeding up anything else will not help until the bottleneck moves.

Testers do not always fix bottlenecks, but they find them by watching which resource saturates first while load rises: CPU pinned at 100 percent, a queue that keeps growing, threads all waiting on the same lock. A good performance report says "response time doubled at 300 users because the database CPU was saturated", not just "it got slow".

Try it: watch a queue turn load into waiting

A server that handles one request at a time is the simplest bottleneck. Each request needs 50 ms of work. This stand-in feeds it requests at different arrival rates and prints how long requests wait. Below the server's capacity (20 requests per second) the waiting is small; above it, the queue grows and response time keeps rising.

JS One server, rising load

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice what happens just above 20 requests per second: every request used to take exactly 50 ms, and suddenly the average jumps past a second and keeps growing for as long as the test runs. In this tidy simulation arrivals are evenly spaced; in real traffic they are bursty, so waiting appears even before the nominal limit. That is why real systems are rarely planned to run near 100 percent capacity.

Practical advice for manual and automated testers

  • Define goals first. "Fast enough" is not a requirement. Agree on percentiles, request types and user counts with the product owner.
  • Use a realistic environment and data. A test on a laptop with ten database rows predicts nothing about production. See test data and environments.
  • Model real behavior. Users pause between actions, and different pages get different traffic. A flood of identical requests can be misleading.
  • Warm up, then measure. Caches and just-in-time compilers make the first minutes unrepresentative.
  • Change one thing at a time, and keep results so you can compare releases and spot regressions early.
  • Do not load-test systems you do not own (third-party APIs, other people's websites) without permission.

Typical tools you will meet are JMeter, k6, Gatling and Locust. They are outside this concepts track, but all of them report the same figures you computed above.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why do performance reports usually include percentiles such as p95 and not just the average?

    A few very slow requests barely move the average, yet those are the requests that frustrate users. p95 and p99 expose that tail.
  2. 2. Which test applies expected, planned traffic and checks the system meets its targets?

    A load test uses the traffic the system is meant to handle. Stress goes beyond it, spike jumps suddenly, and soak runs for a long time.
  3. 3. A memory leak that only exhausts memory after eight hours is most likely to be found by which test?

    Slow resource leaks need time to show up. Running normal load for hours or days is exactly what a soak test is for.
  4. 4. Which requirement is the most testable?

    It names a percentile, a request and a load level, so a test can pass or fail it. The others are vague.

Summary

  • Performance testing measures response time, throughput and resource use, not correctness.
  • Report percentiles (p50, p95, p99) because the average hides the slow tail.
  • Load, stress, soak and spike tests answer different questions about expected traffic, limits, endurance and sudden surges.
  • A bottleneck is the resource that saturates first; find it by watching resources as load rises.
  • Write performance requirements with a percentile, a request and a load level, and test in a realistic environment.

Next: Security Testing Basics.