Load testing — study guide

The concept's fragments, read in order.

For your capstone Take your own app to production

Your app's limit is a guess until a load test measures it, and the measurement belongs on the staging copy your pipeline deploys, not on the app your users are using. What comes out, the rate where it bends and the resource that sets it, is what capacity planning starts from.

Say you run an arrival-rate test against one instance on staging at 30, then 40, then 50 requests per second, with the mix of searches, lists and saves your access logs show. At 30, p95 sits at 180 ms with no errors. Between 40 and 50 it turns sharply upward to 900 ms while successful throughput flattens near 45, and the app container's CPU reads 98 percent while the database sits at 40. That is the knee, and the instance's own CPU is what sets it.

Pretend traffic, real system

Your app works on your machine, where it has exactly one user: you. A load test is how you find out what happens when it has many at once. You point a tool at a running copy of the app, have it send deliberate, synthetic traffic, and measure how quickly the app answers, how often it fails, and at what level of traffic it stops meeting the targets you set for it.

That is a different question from the one ordinary tests ask. They check that a request gets the right answer. A load test assumes the answers are right and asks whether they stay fast and reliable when requests pile up, and which part of the system gives way first when they stop being so. It works like a fire drill: the stressful event happens deliberately, on your schedule and with everyone watching, so the real one is not the first time anyone has seen it.

Doing it well takes three decisions. What traffic to pretend: the mix, the rate, and the data behind it. What shape to apply over time: steady at the expected peak, climbing past it, held for hours, or arriving all at once. And how to read the results, which is where most of the craft lives, because an average latency can look healthy while a meaningful share of users wait. Underneath all three sits one rule: aim the test only at systems you own or have been given permission to test.

Deciding what traffic to pretend

A load test is only as honest as its workload model: the description of the traffic it sends. The model says which requests, in what proportions, at what rate, with what pauses between them, and against how much data. Get it wrong and the test returns precise numbers about traffic your app will never see.

Start from what real traffic already looks like, because your observability is recording it. Request rates per endpoint and access logs tell you the mix: how many requests are cheap reads, how many are searches, how many are writes that touch the database. Real users follow journeys, such as logging in, listing things and saving one, rather than calling a single endpoint in a loop, and a test that hammers only the cheapest endpoint mostly proves that the cheapest endpoint is cheap. Where the model imitates people, it includes think time, the pause between one action and the next, and varies it rather than fixing it at one value.

The data behind the requests matters as much as the requests. A test database holding a few hundred rows fits comfortably in memory, so every query is fast and the test flatters the app; give it a production-like size and shape, with realistic row counts and the same hot and cold records, built from synthetic or sanitized data rather than real personal data. Plan how the data is reset between runs, so each run starts from the same place.

Finally the model says how load arrives over time: ramp up gradually, hold the target long enough to see steady behavior, then ramp down and check that the app recovers. A workload model is a claim about your users, and it deserves the same scrutiny as any other claim.

Arrival rate or a fixed crowd

the same slowdown, two ways of sending traffic app slows down closed: one virtual user sends, waits for the reply, then sends again each box: one request, sent to reply only 2 sent while slow the test eases off by itself open: requests arrive on a fixed schedule, whatever the app is doing each arrow: one request arrives requests waiting 6 sent while slow, queued, and timed from when each was due time (not to scale)
Not drawn to scale. During the same slowdown, a closed-model virtual user that waits for each reply sends only 2 requests, while an open model keeps sending on schedule, sends 6, and the waiting requests pile up in a queue.

Load tools generate traffic in one of two ways, and the choice changes what the results mean. A closed workload model keeps a fixed number of virtual users, simulated clients that each send a request, wait for the reply, and only then send the next. An open workload model sets an arrival rate instead, say 50 new requests per second, and sends on that schedule whether or not earlier requests have finished.

The difference only shows when the app slows down, which is the moment you care about. Suppose replies slow from a tenth of a second to a full second. Each closed-model virtual user now spends most of its time waiting, so it sends far fewer requests: the test quietly lowers its own load exactly when the system is struggling. It works like a restaurant with a fixed set of diners who each order again only once their last dish arrives: when the kitchen slows down it simply receives fewer orders, so it never looks as overwhelmed as it would with walk-in customers arriving regardless. The requests that would have arrived during the slowdown are never sent, so they are never measured, and the latency report looks better than the experience real arrivals would have had. This is called coordinated omission: the load generator coordinates with the struggling system and omits the samples that would have been worst.

An open model does not wait. Requests keep arriving on schedule, so a slowdown shows up as a growing queue and honestly long latencies. Tools built to avoid coordinated omission go one step further and time each request from the moment it was due to be sent, so any delay before sending still counts against the result.

Neither model is wrong in general. A closed model fits clients that truly wait for each reply before asking again, such as a fixed pool of workers. Public traffic to an HTTP API does not wait: strangers on the internet do not hold their request until your server has finished someone else's. For your app, an arrival-rate model is the honest default.

Load, stress, soak and spike

four shapes of test, four questions each panel: offered load (up) over time (across); dashed line = expected peak load: ramp to the expected peak, hold peak does it meet its targets at peak? stress: step past the peak until it breaks peak where is the limit, what fails first? soak: ordinary load held for hours peak does anything slowly leak or fill up? spike: sudden surge, then back peak does it survive the surge and recover?
Four test shapes as offered load over time: load ramps to the expected peak and holds, stress steps past the peak until it breaks, soak holds an ordinary load for hours, and spike jumps suddenly far above normal and drops back.

The same tool and the same workload model can be run in different shapes over time, and each shape answers a different question. Four have standard names. They are not interchangeable: a clean result from one says nothing about the question another one asks.

A load test, in the narrow sense, ramps up to the traffic you expect at peak and holds it there. For your app, that means roughly 50 requests per second, held long enough to see steady behavior. It answers the plainest question: at the load we expect, does the app meet its targets for response time and error rate? A stress test keeps going past that peak, often in steps, until the app stops meeting its targets or starts failing. It answers where the limit is, what fails first, and whether the app recovers once the load drops back.

A soak test, also called an endurance test, holds an ordinary level of load for hours or longer. Short tests miss faults that need time to build up: memory that climbs and never levels off, database connections that are not returned to their pool, logs or temporary files slowly filling a disk. The signal is a trend, a line that keeps rising, rather than any single bad reading. A spike test jumps abruptly from normal load to a sudden surge and back again, and answers whether the app survives the surge and returns to normal afterward rather than staying broken once the crowd has gone.

Most apps need all four eventually, but in an order: a load test at expected peak first, because if that fails, pushing harder tells you little you can act on yet.

Read the tail, not the average

one test run: how long each request took requests latency (ms) 0 200 400 600 800 mean ~200 ms target 300 ms p95 ~470 ms p99 ~700 ms the slowest 5% of requests the mean passes the target; the p95 does not
A latency histogram with most requests fast and a long tail of slow ones: the mean sits under the 300 ms target while the p95, which only the slowest 5 percent of requests exceed, lies well past it.

A load test produces thousands of latencies, not one, and they are not spread evenly. Most requests finish quickly; a smaller number take much longer, stretching out into a long tail of slow ones. The average folds that tail into the fast majority, so it can sit comfortably under your target while a real share of users wait far longer than it suggests.

Percentiles describe the distribution directly. The p95 latency is the value at or below which 95 percent of requests finished, so one request in twenty was slower than it. The p50 is the median, the typical request, and the p99 is the value that only the slowest one request in a hundred exceeds. A target of p95 under 300 ms for your app is therefore a statement about the many, not the average: at least 95 of every 100 requests must finish within 300 milliseconds.

Percentiles have a trap of their own: they cannot be averaged. The p95 of each of two containers, or of each minute of a test, averaged together is not the p95 of the whole run, because a percentile comes from ranking every request, and once each group is reduced to one number that ranking is gone. To get the overall figure, combine the raw measurements, or the histogram buckets your metrics already keep, and compute the percentile from the combined distribution.

Read errors next to latency, every time. An overloaded server may answer with a quick 503 in a few milliseconds instead of a slow success, and those fast failures drag the latency figures down just as the app starts to fail. Fast failures distort the latency figures, so read the latency of successful requests next to the error rate, and remember that a timeout is both an error and a very slow request.

Where it bends

ramping up the load until it bends the knee: a resource saturates p95 latency latency target nearly flat: requests rarely wait queues form, latency shoots up requests per second sent completed keeps pace with sent completed flattens, and can fall expected peak offered load (requests sent per second)
As offered load rises, p95 latency stays nearly flat and then turns sharply upward at the knee, the same point at which completed throughput stops following the load sent and flattens and can fall.

Ramp up the offered load, the rate at which the test sends requests, and plot two things against it: throughput, the requests completed successfully per second, and p95 latency. At first the picture is dull. Throughput rises in step with what is sent, and latency barely moves, because each request finds the system free and rarely waits.

Then a resource approaches full use, and requests start to queue behind each other. Queueing does not grow gently: waits stay short while the resource has slack and multiply as it nears full use, which capacity planning works through in numbers. That is why the latency curve has a knee rather than a slope: it runs nearly flat and then turns sharply upward over a small increase in load. It behaves like the checkout lines at a supermarket: while a cashier is often free you walk straight up, but once every cashier is busy nearly all the time, a few more shoppers stretch the lines to the back of the store.

Past the knee, throughput stops rising even though the test keeps sending more. Requests wait, time out, are retried, and compete for the same busy resource, so successful throughput flattens and can even fall while latency and errors climb. That point, where the app stops turning more traffic into more completed work, is where it bends.

The test shows where it bends; the system's own meters show why. During the run, watch CPU, memory, disk and network for each part of the system, the app's containers and the database alike. Whichever one is saturated at the knee is the bottleneck, and you name it exactly as you would on a single machine. Relieve it, run the test again, and expect the knee to move rather than vanish, because a different resource is now the slowest.

Where to aim it

A load test is traffic designed to strain a system, and from the outside it is hard to tell apart from an attack. So the first rule is plain: only load-test systems you own, or ones whose owner has explicitly given you permission in writing. Cloud providers generally let you load-test your own resources with realistic traffic, but treat traffic meant to overwhelm a target as denial-of-service, which they prohibit or allow only through their own approved routes. Their rules differ and change, so read your provider's current policy before a large test.

Aim at a production-like copy, not at production. A staging environment running the same container image your pipeline promotes, with a realistically sized database, lets you find the bend without anyone else finding it with you. A test that discovers the limit of production discovers it for your users too. Check that staging shares no database, cluster, load balancer or third-party quota with production; if it does, you are load-testing production. If you ever must test production itself, do it with a plan: an agreed window, small steps, someone watching the meters, and a way to stop the traffic at once.

The same care applies to anything your app calls. If it sends email or takes payments through an outside service, load-test traffic would burn through quotas, cost money, trip rate limits and disturb that provider's other customers, and the provider's slowness would show up in your results as if it were yours. Replace such services during the test with a stand-in that answers with realistic delays and occasional failures; one that answers instantly and always succeeds makes your app look faster and sturdier than it is.

Finally, check the tool itself. The load generator can run out of CPU, memory or network before your app does, at which point the test is measuring the generator. Run it on a separate machine from the system under test, watch its meters as well, and confirm that the rate it actually achieved matches the rate you asked for.

Before your users find it

Your app has a few thousand daily users and is growing, with a peak of about 50 requests per second and a target of p95 under 300 ms. What you do not yet know is where it bends. Until something measures it, the limit is a guess, and the first measurement will otherwise be taken by your users on a busy day.

A load test replaces the guess with a fact. Build the workload model from the request mix your observability already records, send it at an arrival rate rather than with a fixed crowd, and aim it at the staging copy your pipeline deploys. Hold it at peak to check the target, step past peak to find the knee, hold an ordinary load overnight to catch slow leaks, and throw in a sudden surge to see whether the app recovers. Read p95 and the error rate together, and watch the meters on the app's containers and the database to name which resource gives way first.

What comes out is the rate at which your app stops meeting its target, and the resource that sets that limit. That pair of facts is the measured input that later decisions about how much to run build on. It is also perishable: each significant change to the code, the queries or the infrastructure can move the bend, so the test is worth repeating rather than running once. The point of all of it is in the name of the exercise: find where it bends before your users do.

Next on your path to Take your own app to production: