Skip to main content

Module cache

Module cache 

Source
Expand description

The Metrics endpoints’ buckets kept between requests: a bucket whose rows are all written doesn’t change, so each request reads only the buckets since the last final one (the user, 2026-11-15: metrics mustn’t weigh on schedr; 30 days of 100 processes took seconds a request on SQLite, and the Deployments page asks every 15 seconds in each tab).

A bucket is final once it ended FINAL_AFTER ago: a minute sample is stored within the sampler’s grace of its minute (a webserver’s late one; ROLL_GRACE), a rollup once, and buckets are aligned to the epoch, so a later request’s buckets are the same ones. A request for a key waits for one already reading it, so many tabs cost one read.

Structs§

CacheLimits
When the cache’s buckets are final, and how much it keeps (decision 493).
Entry
One key’s final buckets.
Key
What is asked for: the samples of each process (all, or one) or the totals, over a range.
SeriesCache
The kept buckets of every key.

Constants§

FINAL_AFTER
How long after a bucket’s end its rows are all stored: the sampler’s grace (2 minutes) and a minute’s write, with room for the clocks of the processes writing them to differ (Codex’s review: a webserver stamps its own sample by its clock). A sample stored later than this misses its rollup too (2 minutes), and a webserver that read past it shows it once it starts again.

Functions§

final_to
The first bucket not final at to, in buckets of bucket_s, final after their end.
keep_buckets
Keeps buckets’ final ones (before final_to) of a range starting from in entry, unless more than most.
merged
kept and read (from where kept ends) as one list by process and time, those before from left out.
merged_latest
Each process’s latest sample: kept’s, replaced by a later one read, those before from left out.
merged_totals
kept and read totals as one list by time, those before from left out; the final ones kept in entry.