Measure latency with two sequential stages
Check units and version numbers as you type. · 176 words
Latency is the time from sending a request to receiving its final result. Imagine a museum app that identifies an object in a photo. Stage 1 runs a vision model and takes 120 ms; stage 2 uses that label to choose a description and takes 45 ms. Because the stages are sequential, the processing time is 120 + 45 = 165 ms. This calculation assumes each stage starts only after the previous stage finishes. It also excludes device and network delays unless those times are measured too.
For reliable operation, measure many requests instead of trusting one stopwatch reading. In a second test, 100 photo requests have a 95th-percentile end-to-end latency of 240 ms: 95 of them finish within that time, while 5 finish later. Put timestamps at request arrival, stage completion, and final response to locate delays. Do not add separate percentiles, such as 150 ms plus 80 ms, and call the sum a 95th percentile. Different requests may be slowest in different stages, so use full request traces or directly measure the end-to-end percentile.
Check your recall
A request spends 90 ms in preprocessing and then 35 ms in inference. What is its sequential processing latency?
Check your answer
Its sequential processing latency is 90 ms + 35 ms = 125 ms, excluding any unmeasured network or queueing delay.
Sources and credits
Original KeyTouch lesson. Background reading · Google · Rules of Machine Learning.