From a new model release to the page: measuring the whole weather cycle

A deterministic ledger separates elapsed time to visibility, summed phases, parallel intervals and uncovered time.

A conceptual editorial scene about measuring the complete path to the reader.

A weather importer can finish decoding quickly while the page continues to display the previous release. Normalisation, result preparation, switching the visible version and checking the response sit between those events. A stopwatch that starts after downloading or stops after writing answers only part of the question: “when did the reader receive the new data?”

Another trap is to add every phase’s duration. Parallel downloads overlap with decoding, and the worker’s overall span already includes its internal operations. The sum can exceed the entire cycle’s duration without a clock error.

We will build our own deterministic interval ledger. It calculates different timing measures and checks the visibility boundary. All timestamps below are supplied numbers in a synthetic fixture. We executed the analysis of those numbers and tests of the algorithm; this experiment measured no production trace, forecast download or real page.

Agree on the start and end first

A weather release has several distinct moments: the model’s nominal run time, availability at the provider, discovery by our service and visibility on a page. They do not become one timestamp merely because they concern the same forecast.

In the laboratory, zero means the system discovers the new release. The end is an observation of the expected revision across the expected public scope. Delay before discovery is excluded. If a measure must start at the provider’s actual publication, that starting point needs separate evidence and an explanation of the observation’s precision.

The input contains expected_revision, expected_scope and an optional visibility event. Its revision and scope must match the expected values. In the fixture, these are release-b and six-city-pages. The scope name is a trusted synthetic label: the example opens no six URLs and proves no page completeness.

This contract prevents the cycle from finishing merely because a worker returned success. A visible old release does not finish the update either. Reading one city also does not confirm a different, wider scope without an appropriate verification rule.

A ledger with parallel intervals

The explanatory table uses seconds; JSON stores integer milliseconds. Every interval is half-open: the start is included and the end excluded. Two operations that touch at one instant create no extra overlap duration.

Work Start, s End, s Duration, s
Receive field A 10 50 40
Receive field B 20 70 50
Decode A 30 65 35
Decode B 55 80 25
Normalise 80 95 15
Prepare results 95 104 9
Switch the public version 108 112 4
Check the public representation 116 120 4

This is a fictional pipeline in which receiving and processing partly overlap. The table does not claim that a particular real decoder can start before its entire message arrives. For a real source, those dependencies must be instrumented according to its actual behaviour.

Besides the eight work intervals, there are two containers: overall observation from 0 to 140 seconds, and a worker from 20 to 104. They structure the ledger but are not added to the durations of their child operations.

Six timing measures instead of one

Elapsed time to visibility is calculated without adding phases:

elapsed = window_end - cycle.start_ms if accepted else None

If the accepted visibility event is at 120 seconds, we obtain 120 seconds from the start. Overall observation continues until 140, but those extra twenty seconds do not extend an already completed measure. Work intervals crossing the visibility boundary contribute only up to that boundary.

The eight work durations sum to 182 seconds. This answers how much duration is recorded across individual intervals. It is not CPU time: a receiving interval can include waiting, and several operations can run simultaneously.

The union of work intervals occupies 102 seconds. Each stretch of time enters that total once, even when three operations are active. Another 18 seconds inside the cycle have no coverage from any selected work interval.

Measure Fixture analysis result
Discovery to expected visibility 120 s
Sum of work-interval durations 182 s
Time covered by at least one work interval 102 s
Time with two or more active intervals 50 s
Excess of the sum over the union 80 s
Uncovered time inside the cycle 18 s

Why does overlap produce both 50 and 80? The first counts each stretch with parallel activity once. The second counts extra contributions to the sum: with three intervals active, each second adds two extra seconds to that sum. Calling both values simply “overlap” without a definition would be ambiguous.

Avoid counting a parent span twice

OpenTelemetry describes a span as an operation with a start, end and context; child spans can describe its components. Adding the overall operation’s time to its details double-counts work even without parallel threads.

Our ledger therefore has an explicit role: work or container. Only work contributes to the sum and union. This is a teaching accounting rule; a span’s name cannot determine it automatically. If a container performs unrecorded work itself, we need separate instrumentation or an honestly uncovered interval.

The validator checks unique IDs, an existing parent, absence of cycles and containment of a child interval inside its container. That last condition belongs specifically to this closed format. This is not a validator for arbitrary OpenTelemetry traces: the Tracing API allows child spans to continue after their parent ends. A real asynchronous trace needs a different relationship model and corresponding accounting.

The algorithm traverses sorted work starts and ends, tracks the number of active intervals, and counts the length of each stretch between adjacent events. Expected values in expected.json are literal numbers, not results constructed by that same traversal.

Uncovered time does not mean idle CPU

Our ledger’s uncovered stretches are 0–10, 104–108 and 112–116 seconds. These are concrete places for further investigation. They might correspond to waiting for a start, an unrecorded transition or the interval before checking visibility. Subtraction alone cannot establish the cause.

We do not call those 18 seconds CPU idle time, network time or lost data. An absent span means an absent selected observation, not proven absence of work. The union of intervals is not the critical path either: causal-delay analysis requires dependencies between tasks, which this arithmetic does not reconstruct.

Both perspectives are useful. The outer interval answers the reader’s question, while phase measures help identify who owns the cost. Optimising the largest summed span without considering overlap is insufficient: that span may not determine when the new version appears.

The budget needs the same boundary as the promise

The teaching budget is 100 seconds. The worker takes 84 seconds, from 20 to 104, and fits that number. The entire path to visibility takes 120 seconds and does not fit. These are two correct conclusions about different intervals, not a contradictory test.

The 100-second threshold is a fixture condition, not a recommended SLA. A real product needs agreement on the start, end, city scope, fields, horizons and cache state. A cold start and reuse of previously received data are different scenarios; their durations should not be added into one imaginary execution.

Without the expected visibility event, the result contains elapsed_to_visible_ms: null and within_budget: null. Only the interval observed so far is known; there is no completed latency. Substituting zero or worker completion would hide an unfinished update. A mismatching revision or scope does not create success either.

One clock domain and the boundary of the evidence

Every record in our ledger belongs to one clock_domain. Mixed domains are rejected. For local durations, Python provides a monotonic clock unaffected by changes to system time. Its reference point is not a calendar date; differences between readings are used.

This does not permit direct subtraction of monotonic readings from different servers. Distributed measurement needs a common observation method or an account of timestamp synchronisation and uncertainty. Our example performs no such reconciliation and exports no OpenTelemetry data.

Likewise, a visibility label is not independent proof of a site response. A real observer must check the required revision through the agreed public path, retain the verification scope, and distinguish an old cache entry from new data. Here the event is supplied to test the logic, and there are no network requests.

Scope of the algorithm check

The local check used the Python standard library.

Twenty-nine test methods ran under Python 3.12.14. They cover the literal report, parallel and sequential intervals, container exclusion, time gaps, a shifted clock origin, clipping after visibility, a mismatching revision, absent visibility and invalid timing records.

The result is a checked method for defining measurement boundaries. Before speeding up one component, we can establish what the reader is waiting for, where the cycle ends and which parts of its duration are explained by observations. Actual numbers for that cycle still require a separate execution.

  1. Platform Engineering From HTTP request to worker: tracing one application operation
  2. Weather An optimization that failed validation: evaluating speed across the whole path
  3. Weather Switching a whole forecast: snapshots, checkpoints and crash recovery
  4. Weather The process finished, but was the whole forecast updated?