From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 3FEC81FF170 for ; Thu, 21 Aug 2025 11:54:27 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5064B1CC56; Thu, 21 Aug 2025 11:54:24 +0200 (CEST) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Date: Thu, 21 Aug 2025 11:53:18 +0200 Message-ID: <20250821095319.134215-23-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250821095319.134215-1-l.wagner@proxmox.com> References: <20250821095319.134215-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1755769978195 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.024 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_SHORT 0.001 Use of a URL Shortener for very short URL SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [PATCH proxmox-datacenter-manager v6 22/23] metric collection: skip missed timer ticks X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" The default behavior of `tokio::time::Interval` when a tick is missed is 'burst', which is to shorten the timer intervals until the original alignment is restored, while keeping the *number of ticks* the same the same as expected. Example from the official tokio docs [1] for burst mode: Expected: | 1 | 2 | 3 | 4 | 5 | 6 | Actual: | work ---| delay |work|work|work-|work-----| For metric collection, we do not really gain anything from bursting missed ticks. For us, 'skip' is fine. There, the alignment is immediately restored by skipping any ticks that have been missed: Expected: | 1 | 2 | 3 | 4 | 5 | 6 | Actual: | work ---| delay |work---| work----| work----| https://docs.rs/tokio/latest/tokio/time/enum.MissedTickBehavior.html Signed-off-by: Lukas Wagner Reviewed-by: Maximiliano Sandoval --- Notes: New in v2. server/src/metric_collection/collection_task.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/src/metric_collection/collection_task.rs b/server/src/metric_collection/collection_task.rs index db65af24..59493162 100644 --- a/server/src/metric_collection/collection_task.rs +++ b/server/src/metric_collection/collection_task.rs @@ -9,7 +9,7 @@ use tokio::{ mpsc::{Receiver, Sender}, oneshot, OwnedSemaphorePermit, Semaphore, }, - time::Interval, + time::{Interval, MissedTickBehavior}, }; use proxmox_section_config::typed::SectionConfigData; @@ -166,6 +166,13 @@ impl MetricCollectionTask { fn setup_timer(interval: u64) -> (Interval, Instant) { log::debug!("setting metric collection interval timer to {interval} seconds.",); let mut timer = tokio::time::interval(Duration::from_secs(interval)); + + // If we miss a tick because a previous collection run took too long, we want to + // tick as soon as possible, but we do not need to repeat missing ticks. + // We do want to stay aligned, though. + // https://docs.rs/tokio/latest/tokio/time/enum.MissedTickBehavior.html#variant.Skip + timer.set_missed_tick_behavior(MissedTickBehavior::Skip); + let first_run = task_utils::next_aligned_instant(interval); timer.reset_at(first_run.into()); -- 2.47.2 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel