pub struct Gcra { /* private fields */ }Expand description
GCRA parameters for one limit, in microseconds. emission_interval is the steady-state time
per request (period / count); tolerance is how far the TAT may run ahead of now before a
request is rejected (emission_interval * burst), i.e. the burst allowance.
Implementations§
Source§impl Gcra
impl Gcra
Sourcepub fn from_parts(count: u64, period: Duration, burst: u64) -> Result<Gcra>
pub fn from_parts(count: u64, period: Duration, burst: u64) -> Result<Gcra>
Build directly from a count, a period and a burst.
from_rate parses a "N/unit" string whose grammar stops at hour, which cannot express
the CA issuance limits in crate::acme_budget — those are per 3 hours and per 7 days. This
is the same arithmetic without the string, so all GCRA maths stays in this one file rather
than being reimplemented next to the thing that needs a longer window.
Sourcepub fn next_admit_at(&self, stored_tat: Option<u64>, now: u64) -> u64
pub fn next_admit_at(&self, stored_tat: Option<u64>, now: u64) -> u64
The earliest time (µs) at which this bucket would admit, given its stored TAT.
GCRA admits when now >= tat + emission_interval - tolerance. Deriving that at the call site
is easy to get wrong by exactly one emission interval — which yields a retry instant in the
past and turns a deferral into a hot loop against the CA. It lives here, next to
gcra_admit, so the two cannot disagree.
Sourcepub fn remaining(&self, stored_tat: Option<u64>, now: u64) -> u64
pub fn remaining(&self, stored_tat: Option<u64>, now: u64) -> u64
How many more admissions the bucket currently allows, for reporting.
Derived rather than stored: tolerance / emission_interval is the burst, and the distance
between now and the stored TAT says how much of it has been spent. Used for the
remaining/consumed_ratio metrics, so an operator sees the budget draining before it is
gone rather than after.