Sub topic 12
Validating with measurement and load tests, then revising targets
This chapter assumes you know how to read percentiles, SLIs and SLOs, Little's law, and latency budgets from earlier chapters. Targets set on paper are guesses. This chapter covers how to check them against real behavior and how to change them when they are wrong.
Measure first, in production if you can
Real traffic is the best evidence. Record latency per request, not per minute, so you can compute percentiles yourself. Averaging per-minute p99 values gives a number that is not the p99 of the whole period. Prefer histograms with fixed buckets, which can be merged across servers. Averages of percentiles cannot be merged.
Measure at the point the user experiences. A server-side timer misses queueing in the load balancer and the network. Record the following for each component in your latency budget:
- Latency percentiles (p50, p99, and p99.9 if traffic is high enough).
- Request rate, including the peak.
- Error rate.
- In-flight requests, to compare with the Little's law estimate.
Load test against the targets
A load test sends controlled traffic to a test environment and records the same metrics. Its goal is to answer one question: does the system meet the SLO at the peak rate, with headroom?
A useful test follows these rules:
- Use the peak rate from your load estimate, then 1.5 to 2 times that rate to check headroom.
- Use an open model, which sends requests at a fixed rate whatever the responses do. A closed model, where each virtual user waits for a reply before sending again, slows down when the system slows down. It hides the very queueing you want to see. This is sometimes called coordinated omission.
- Use a realistic request mix and realistic data sizes. A cache that is warm in the test but cold in production gives false results.
- Run long enough to reach steady state, and ramp up in steps so you can see where latency bends upward.
Check results against the targets
The script below turns raw results into SLI values and compares them with the SLO. It uses the nearest-rank percentile from earlier chapters.
import math
def percentile(samples, p):
ordered = sorted(samples)
rank = math.ceil(p / 100 * len(ordered))
return ordered[rank - 1]
# Results of a load test at peak rate: 1000 requests
latencies_ms = [40] * 980 + [280] * 15 + [900] * 5
ok_flags = [True] * 998 + [False] * 2 # 2 failed requests
target_p99_ms = 300
target_success = 0.999
p99 = percentile(latencies_ms, 99)
success = sum(ok_flags) / len(ok_flags)
print("p99 ms:", p99, "target:", target_p99_ms, "pass:", p99 <= target_p99_ms)
print("success:", success, "target:", target_success, "pass:", success >= target_success)The run prints a latency pass (p99 is 280 ms) and an availability fail (success is 0.998). The failure points to a different problem than slowness. The fix may be timeouts, connection pool limits, or an error path, not more speed.
Find the bottleneck, then compare with the model
When a target fails, find which component used its budget. Compare each component's measured p99 with its allocation. Then compare measured in-flight requests with the Little's law value (arrival rate times average latency). A large gap means one of the inputs is wrong. For example, the real arrival rate may be higher, or a hidden queue may be adding wait time.
Revise the target, the design, or the requirement
When measurements disagree with targets, you have three options:
| Situation | Response |
|---|---|
| The system misses the target and a fix is affordable | Change the design: add a cache, shrink a fan-out, add capacity. |
| The system misses the target and the fix costs too much | Renegotiate the target with the product owner, using the measured numbers. |
| The system beats the target by a wide margin | Tighten the SLO only if users would notice. Otherwise spend the slack on cost or release speed. |
Do not loosen a target only to make a dashboard green. Tie each change back to the user requirement that started it. Record the old value, the new value, and the evidence.
Repeat the loop on a schedule and after major changes, such as new features, traffic growth, or a new dependency. Targets that were right last year drift as load and code change.
Exercise
A load test uses 200 virtual users. Each sends a request, waits for the reply, then sends the next. Under load the server slows down and the report shows a p99 of 250 ms, within a 300 ms target. Why might this result be misleading, and what change would fix the test?
Show answer
Each user waits for a reply, so when the server slows down, the test sends fewer requests. The arrival rate drops exactly when queues would build, and the slow period is under-sampled. Switch to an open model that sends requests at a fixed rate, such as the planned peak rate, whatever the responses do. Then the p99 includes the queueing a real traffic spike would cause.