pub struct Governor { /* private fields */ }Expand description
The adaptive concurrency governor — the inline thread::scope closure
that used to live in [crate::pipeline::chunked::exec::run_chunked_parallel]
turned into a self-contained, testable abstraction.
Why a struct (not just functions): the decision policy
([GovernorState]) and the sample cadence (sample/poll intervals,
RIVET_GOVERNOR_INTERVAL_MS env override) are runtime-coupled — the
poll interval must be clamped to the sample interval, and the decision
state is mutated across ticks. Bundling them into one type makes the
“what to test, what to fake” boundary obvious: the source is the
dependency, the runner-side side effects are a callback.
Implementations§
Source§impl Governor
impl Governor
Sourcepub fn new(start: usize, floor: usize, ceiling: usize) -> Self
pub fn new(start: usize, floor: usize, ceiling: usize) -> Self
Build a governor that starts at start, clamped into [floor, ceiling], and uses the env-tunable sample cadence
(RIVET_GOVERNOR_INTERVAL_MS; falls back to
[GOVERNOR_SAMPLE_INTERVAL_MS]). The poll interval is clamped to
the sample interval so a tiny override (used in deterministic live
tests) actually polls that fast, instead of being capped at the
default [GOVERNOR_POLL_MS].
Sourcepub fn tick(&mut self, sample: Option<u64>) -> Option<(usize, usize)>
pub fn tick(&mut self, sample: Option<u64>) -> Option<(usize, usize)>
Pure decision step: fold one sample into the state. Returns
Some((from, to)) on a parallelism transition, None otherwise.
Mirrors [GovernorState::observe]; exposed at the Governor
surface so tests can drive the policy without entering run.
Sourcepub fn run<S, Stop, Decide>(
&mut self,
source: &mut S,
stop: Stop,
on_decision: Decide,
)
pub fn run<S, Stop, Decide>( &mut self, source: &mut S, stop: Stop, on_decision: Decide, )
Drive the sample loop until stop returns true. On every
parallelism transition the on_decision(from, to) callback fires
— the runner binds it to its semaphore-resize + log +
decision-log machinery. Polls every poll_interval, samples
every sample_interval. The stop predicate is re-checked after
each poll sleep so a finished run exits within one poll quantum.