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 2F7ED1FF165 for ; Thu, 14 Aug 2025 15:30:57 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 846E81357A; Thu, 14 Aug 2025 15:32:34 +0200 (CEST) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Date: Thu, 14 Aug 2025 15:31:42 +0200 Message-ID: <20250814133142.386650-24-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250814133142.386650-1-l.wagner@proxmox.com> References: <20250814133142.386650-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1755178278059 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.022 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 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 v5 23/23] metric collection: use JoinSet instead of joining from handles in a Vec 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" This lets us process finished tasks in the order they finish, not in the order they were spawned. Suggested-by: Wolfang Bumiller Signed-off-by: Lukas Wagner Reviewed-by: Maximiliano Sandoval --- Notes: New in v2. .../src/metric_collection/collection_task.rs | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/server/src/metric_collection/collection_task.rs b/server/src/metric_collection/collection_task.rs index 59493162..da6cc850 100644 --- a/server/src/metric_collection/collection_task.rs +++ b/server/src/metric_collection/collection_task.rs @@ -9,6 +9,7 @@ use tokio::{ mpsc::{Receiver, Sender}, oneshot, OwnedSemaphorePermit, Semaphore, }, + task::JoinSet, time::{Interval, MissedTickBehavior}, }; @@ -201,7 +202,8 @@ impl MetricCollectionTask { remotes_to_fetch: &[String], ) { let semaphore = Arc::new(Semaphore::new(MAX_CONCURRENT_CONNECTIONS)); - let mut handles = Vec::new(); + let mut handles = JoinSet::new(); + let now = proxmox_time::epoch_i64(); for remote_name in remotes_to_fetch { @@ -224,29 +226,22 @@ impl MetricCollectionTask { if let Some(remote) = remote_config.get(remote_name).cloned() { log::debug!("fetching remote '{}'", remote.id); - let handle = tokio::spawn(Self::fetch_single_remote( + handles.spawn(Self::fetch_single_remote( remote, status, self.metric_data_tx.clone(), permit, )); - - handles.push((remote_name.clone(), handle)); } } - for (remote_name, handle) in handles { - let res = handle.await; - + while let Some(res) = handles.join_next().await { match res { - Ok(Ok(ts)) => { - self.state.set_status(remote_name, ts); + Ok((name, status)) => { + self.state.set_status(name, status); } - Ok(Err(err)) => log::error!("failed to collect metrics for {remote_name}: {err}"), Err(err) => { - log::error!( - "join error for metric collection task for remote {remote_name}: {err}" - ) + log::error!("join error for metric collection task for remote: {err}") } } } @@ -293,7 +288,7 @@ impl MetricCollectionTask { mut status: RemoteStatus, sender: Sender, _permit: OwnedSemaphorePermit, - ) -> Result { + ) -> (String, RemoteStatus) { let (result_tx, result_rx) = oneshot::channel(); let now = proxmox_time::epoch_i64(); @@ -361,7 +356,7 @@ impl MetricCollectionTask { } } - Ok(status) + (remote.id, status) } } -- 2.47.2 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel