From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pdm-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 45F5C1FF164 for <inbox@lore.proxmox.com>; Fri, 14 Feb 2025 14:08:13 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 81ABE19F6D; Fri, 14 Feb 2025 14:08:13 +0100 (CET) From: Lukas Wagner <l.wagner@proxmox.com> To: pdm-devel@lists.proxmox.com Date: Fri, 14 Feb 2025 14:06:53 +0100 Message-Id: <20250214130653.283012-29-l.wagner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250214130653.283012-1-l.wagner@proxmox.com> References: <20250214130653.283012-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.010 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 v2 28/28] 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 <pdm-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pdm-devel/> List-Post: <mailto:pdm-devel@lists.proxmox.com> List-Help: <mailto:pdm-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox Datacenter Manager development discussion <pdm-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" <pdm-devel-bounces@lists.proxmox.com> This lets us process finished tasks in the order they finish, not in the order they were spawned. Suggested-by: Wolfang Bumiller <w.bumiller@proxmox.com> Signed-off-by: Lukas Wagner <l.wagner@proxmox.com> --- 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 5c6e2762..4e8aa627 100644 --- a/server/src/metric_collection/collection_task.rs +++ b/server/src/metric_collection/collection_task.rs @@ -10,6 +10,7 @@ use tokio::{ mpsc::{Receiver, Sender}, oneshot, OwnedSemaphorePermit, Semaphore, }, + task::JoinSet, time::{Interval, MissedTickBehavior}, }; @@ -267,7 +268,8 @@ impl MetricCollectionTask { let semaphore = Arc::new(Semaphore::new( self.settings.max_concurrent_connections_or_default(), )); - let mut handles = Vec::new(); + + let mut handles = JoinSet::new(); let now = proxmox_time::epoch_i64(); for remote_name in remotes_to_fetch { @@ -290,30 +292,23 @@ 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( self.settings.clone(), 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}") } } } @@ -362,7 +357,7 @@ impl MetricCollectionTask { mut status: RemoteStatus, sender: Sender<RrdStoreRequest>, _permit: OwnedSemaphorePermit, - ) -> Result<RemoteStatus, Error> { + ) -> (String, RemoteStatus) { Self::sleep_for_random_millis( settings.min_connection_delay_or_default(), settings.max_connection_delay_or_default(), @@ -436,7 +431,7 @@ impl MetricCollectionTask { } } - Ok(status) + (remote.id, status) } } -- 2.39.5 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel