Avoid repeated full journal scans and fast ticks in Windows idle
This commit is contained in:
@@ -1291,8 +1291,8 @@ impl Agent {
|
||||
&& !self.helper_apply_unconfirmed
|
||||
&& !self.prepared
|
||||
&& self.running.is_none()
|
||||
&& !self.journal.connection().query_row("SELECT EXISTS(SELECT 1 FROM job_attempts WHERE state IN ('requesting','running','verifying'))",[],|r|r.get::<_,bool>(0))?
|
||||
&& self.helper_probe_at.elapsed() >= Duration::from_secs(30)
|
||||
&& !self.journal.connection().query_row("SELECT EXISTS(SELECT 1 FROM job_attempts WHERE state IN ('requesting','running','verifying'))",[],|r|r.get::<_,bool>(0))?
|
||||
{
|
||||
let agent = self.identity.agent_id.clone();
|
||||
let asset = self.identity.asset_id.clone();
|
||||
@@ -2663,8 +2663,9 @@ impl Agent {
|
||||
let mut heartbeat = Instant::now() - Duration::from_secs(60);
|
||||
let mut previous_cpu = None;
|
||||
let mut heartbeat_after = Duration::from_secs(30);
|
||||
let mut tick = tokio::time::interval(Duration::from_millis(20));
|
||||
tick.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
|
||||
let active_tick = Duration::from_millis(20);
|
||||
let idle_tick = Duration::from_millis(250);
|
||||
let mut next_tick = tokio::time::Instant::now();
|
||||
let mut readiness_at = Instant::now() - Duration::from_secs(5);
|
||||
#[cfg(feature = "system-helper")]
|
||||
let mut update_control_at = Instant::now() - Duration::from_secs(2);
|
||||
@@ -2675,9 +2676,19 @@ impl Agent {
|
||||
running.cancel.store(true, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
let control_pending = self.running.is_some()
|
||||
|| self.prepared
|
||||
|| self.deferred_sync.is_some()
|
||||
|| self.deferred_permit.is_some()
|
||||
|| self.helper_control_pending();
|
||||
#[cfg(feature = "system-helper")]
|
||||
let control_pending = control_pending || self.helper_probe.is_some();
|
||||
let cadence = if control_pending { active_tick } else { idle_tick };
|
||||
next_tick = next_tick.min(tokio::time::Instant::now() + cadence);
|
||||
tokio::select! {
|
||||
Some(completion)=self.completed_rx.recv()=>{self.completed(generation,completion)?;needs_sync=true;},
|
||||
_=tick.tick()=>{
|
||||
_=tokio::time::sleep_until(next_tick)=>{
|
||||
next_tick = tokio::time::Instant::now() + cadence;
|
||||
if !stop.load(Ordering::SeqCst) && self.poll_sync_apply(generation,true).is_err(){self.close_gate();needs_sync=true;}
|
||||
#[cfg(feature = "system-helper")]
|
||||
if !stop.load(Ordering::SeqCst) && self.poll_helper(&channel,generation).await.is_err() {self.close_gate();needs_sync=self.sync.is_some();}
|
||||
@@ -2709,7 +2720,9 @@ impl Agent {
|
||||
if self.sync.is_some() && !self.prepared && !self.helper_control_busy_for_sync() && rmm_agent_windows::job_readiness::refresh_due(needs_sync,sync_at.elapsed(),self.sync.as_ref().and_then(|s|s.validity_deadline()),self.clock.reading().ok().map(|r|r.upper)) {
|
||||
if self.start_sync(&channel,generation).await.is_err(){self.close_gate();needs_sync=true;}else{needs_sync=false;}sync_at=Instant::now();
|
||||
}
|
||||
if Instant::now() >= permit_after && !needs_sync && !self.prepared && self.ready(generation) && jobs::events(self.journal.connection())?.is_empty() && self.journal.count()?==0 {
|
||||
if Instant::now() >= permit_after && !needs_sync && !self.prepared && self.config.enable_jobs
|
||||
&& self.journal.connection().prepare_cached("SELECT EXISTS(SELECT 1 FROM job_attempts WHERE state='accepted' AND cancel_requested=0)")?.query_row([], |row| row.get::<_, bool>(0))?
|
||||
&& self.ready(generation) && jobs::events(self.journal.connection())?.is_empty() && self.journal.count()?==0 {
|
||||
// A transiently stale clock skips this tick; it must not end the session.
|
||||
if let Ok(now)=self.clock.now() && let Some(offer)=jobs::next_at(self.journal.connection(),now)? {
|
||||
let job=self.binding.as_ref().context("JOB_BINDING_REQUIRED")?.job(&offer.payload_bytes)?;
|
||||
@@ -3078,7 +3091,19 @@ async fn run_service_binding(path: &Path, stop: &'static AtomicBool, release_gua
|
||||
ensure!(rmm_agent_windows::echo_probe::protected_scope()? == *scope, "WINDOWS_ECHO_CONFIGURATION_CHANGED");
|
||||
}
|
||||
}
|
||||
let sync=if config.enable_jobs && (!config.windows_echo_probe_only || config.echo_scope.is_some()) {binding.clone().map(|binding|reconcile::ClientSync::new(binding).with_helper_identity(reconcile::HelperIdentity::System))} else {None};
|
||||
let sync = if config.enable_jobs && (!config.windows_echo_probe_only || config.echo_scope.is_some()) {
|
||||
binding.clone().map(|binding| {
|
||||
let sync = reconcile::ClientSync::new(binding)
|
||||
.with_helper_identity(reconcile::HelperIdentity::System);
|
||||
if config.localservice_time_policy.is_some() {
|
||||
sync.with_periodic_idle_integrity_checks()
|
||||
} else {
|
||||
sync
|
||||
}
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let (completed_tx,completed_rx)=tokio::sync::mpsc::channel(1);
|
||||
let mut agent = Agent {
|
||||
config,
|
||||
|
||||
Reference in New Issue
Block a user