Latency and throughput interpretation
Measure throughput and errors together
Throughput is completed work per unit time. Count attempts, completions, failures and the measurement window separately; fast errors can make raw request rate look excellent. In a synthetic trial, 100 attempts finish in 5 seconds and 96 return the expected response. Attempt rate is 20/s, successful throughput is 19.2/s, and failure fraction is 4%. Use wall time, not the sum of individual durations, when requests overlap. A 200 response with the wrong body is also a failed functional check.
attempts, successes, seconds = 100, 96, 5print(attempts / seconds, successes / seconds) # 20.0 19.2print(100 * (attempts-successes)/attempts) # 4.0Read percentiles without hiding the tail
A percentile estimates a position in the sorted distribution. This course uses nearest rank: the p-th percentile is the observation at rank ceil(p*n/100), counting from one. Other tools interpolate differently. With ten synthetic durations, the median by nearest rank is the fifth observation, and p95 and p99 both reach the maximum. A tiny sample cannot resolve rare tail events; report sample size and estimator. Do not average p95 values across workers to estimate fleet p95; merge compatible samples or histogram counts.
from math import ceilms = [5, 6, 7, 8, 9, 10, 11, 12, 14, 80]for p in (50, 95, 99): print(p, sorted(ms)[ceil(p*len(ms)/100)-1])# 50 9; 95 80; 99 80Compare server and upstream timing
Nginx request_time measures server-side elapsed request handling through response logging, including time spent reading client data and sending output. Upstream timing fields describe attempts to the backend and may have multiple values or a missing marker. They are not always scalar numbers. A static response may have no upstream timing. Do not interpret request_time minus upstream_response_time as exact CPU time: stages can overlap and output can be buffered. The following partial http-context log format omits URLs, headers and credentials.
log_format timings escape=json '{"status":"$status","request_s":"$request_time",' '"upstream_s":"$upstream_response_time"}';access_log logs/timing.log timings;Identify the actual bottleneck
A slow client, busy origin, CPU-heavy compression, disk reads, network saturation and a saturated load generator can all reduce observed throughput. Examine utilization, queues and errors along with latency. The synthetic rows below suggest a backend delay, not proof: high upstream time tracks high request time. Check origin service telemetry and repeat with a controlled workload. Timeouts and rejected requests must remain visible, rather than disappearing from the dataset.
Synthetic observations (seconds)request_s upstream_s status0.042 0.036 2000.840 0.815 2001.004 1.000 504- - client timeout (client-side record)Practice and recap
Eight successful responses and two failures complete in two seconds. Successful durations are 4, 5, 6, 7, 8, 9, 10, 50 ms. Compute success throughput, error percentage and nearest-rank p95 of successful samples. Explain the limitation. Check your reasoning against the manual exercise. Next: Controlled optimization.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Latency and throughput interpretation
Distinguish percentiles from means
96 successes in 5 seconds equals what successful throughput?
What is the error fraction for 4 failures in 100 attempts?
Nearest-rank p95 for ten sorted observations is which rank?
Why can upstream timing contain commas?
Can averaging worker p95 values yield exact fleet p95?