Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ impl Controller {
host_cpu_util: self.host_cpu_util,
psi: self.psi,
tick_index: self.tick_index,
scale_poll_secs: self.cfg.scale_poll_secs,
};
let fleet: Vec<_> = self.instances.values().cloned().collect();
let refresh_cgroup = self.cfg.refresh_cgroup_on_each_read;
Expand Down Expand Up @@ -847,13 +848,15 @@ impl Controller {
instance.status.write().await.cooldown_until =
Some(Instant::now() + Duration::from_secs_f64(self.cfg.cooldown_secs));
}
let applied_at = Instant::now();
self.engine
.on_applied(
&instance.id,
AppliedOutcome::DryRun {
action,
prev_thread_count: previous_count,
prev_io_count_total: previous_io_count,
applied_at,
},
)
.await;
Expand All @@ -862,11 +865,12 @@ impl Controller {

match instance.client.set_thread_count(target).await {
Ok(()) => {
let applied_at = Instant::now();
let mut status = instance.status.write().await;
status.thread_count = target;
if matches!(action, ScaleAction::Up(_) | ScaleAction::Down(_)) {
status.cooldown_until =
Some(Instant::now() + Duration::from_secs_f64(self.cfg.cooldown_secs));
Some(applied_at + Duration::from_secs_f64(self.cfg.cooldown_secs));
}
drop(status);
self.engine
Expand All @@ -876,6 +880,7 @@ impl Controller {
action,
prev_thread_count: previous_count,
prev_io_count_total: previous_io_count,
applied_at,
},
)
.await;
Expand Down
20 changes: 20 additions & 0 deletions src/engines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ pub struct EngineTickContext {
pub psi: PsiSample,
/// Monotonically increasing tick sequence number.
pub tick_index: u64,
/// Controller poll interval in seconds (for operator-facing durations).
pub scale_poll_secs: f64,
}

impl Default for EngineTickContext {
fn default() -> Self {
Self {
now: Instant::now(),
min_thread_count: 2,
max_thread_count: 8,
host_cpu_util: 0.0,
psi: PsiSample::default(),
tick_index: 0,
scale_poll_secs: 10.0,
}
}
}

/// One VM's entry in a fleet-wide plan.
Expand Down Expand Up @@ -161,6 +177,8 @@ pub enum AppliedOutcome {
prev_thread_count: u32,
/// Cumulative backend I/O ops before actuation.
prev_io_count_total: u64,
/// Time when the controller recorded the outcome.
applied_at: Instant,
},
/// Actuation was intentionally skipped.
DryRun {
Expand All @@ -170,6 +188,8 @@ pub enum AppliedOutcome {
prev_thread_count: u32,
/// Cumulative backend I/O ops before the proposal.
prev_io_count_total: u64,
/// Time when the controller recorded the outcome.
applied_at: Instant,
},
/// A controller guard deliberately prevented backend actuation.
Blocked {
Expand Down
Loading
Loading