Where did the latency go? — critical path and self time in a waterfall
A waterfall answers three questions at a glance — which span holds time its children do not account for, which children overlap and which wait on each other, and where there is no span at all — and only the chain that does not overlap can be shortened.
The right trace is open on screen. Reading it is a skill, not a glance — the biggest bar is usually a decoy.
Scene 14
Where did the latency go?
- Watch
- Try it
- Predict
- Capture
You are holding the right trace at last — so which line of it do you actually go and fix? Watch the same 3 s checkout get read in four passes. First the bars alone. Then each bar split into the part it spent waiting inside a child and the part it held itself — scene 02 described that second part in plain words and deliberately did not name it; here it gets its name, self time. Then the one chain of spans that each had to wait for the next gets ringed. Then 200 identical calls to the legacy ledger service fold into a single row.
Highlighted lines are the ones running in the diagram right now.
def self_time(span):covered = 0cursor = span.start_msfor child in sort_by_start(span.children):if child.end_ms <= cursor:continuecovered += child.end_ms - max(child.start_ms, cursor)cursor = child.end_msreturn span.duration_ms - covered
def critical_path(span, ends_at):chain = [span]cursor = ends_atfor child in sort_by_finish(span.children, reverse=True):if child.end_ms > cursor:continuechain += critical_path(child, child.end_ms)cursor = child.start_msreturn chain
def collapse_repeats(siblings, fold_repeats):key_of = lambda s: (s.name, s.peer)rows = []for key, group in group_by(siblings, key_of):if not fold_repeats or len(group) < FOLD_MIN:rows += groupcontinuefirst = min(s.start_ms for s in group)last = max(s.end_ms for s in group)rows.append(fold(key, first, last - first,badge=f'×{len(group)}'))return rows
Where this sits in Build a distributed tracing system (Jaeger / Zipkin style)
Scene 14 of 17, in the Store & read act — Key by trace id, find it, read it, distrust it.. The waterfall answers three questions at a glance: which span holds time its children don't account for, which children overlap, and where there is no span at all. Only the chain that doesn't overlap can be shortened.
Up next. You named a culprit from the shape of the bars. Can you trust the bars?
All 17 scenes in Build a distributed tracing system (Jaeger / Zipkin style) · Every curriculum