From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id AF3221FF13E for ; Fri, 06 Mar 2026 09:20:20 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 243551A303; Fri, 6 Mar 2026 09:21:27 +0100 (CET) From: Dominik Rusovac To: pve-devel@lists.proxmox.com Subject: [RFC proxmox 1/3] resource-scheduling: add lab feature Date: Fri, 6 Mar 2026 09:20:44 +0100 Message-ID: <20260306082046.34311-2-d.rusovac@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260306082046.34311-1-d.rusovac@proxmox.com> References: <20260306082046.34311-1-d.rusovac@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1772785223784 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.280 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 RCVD_IN_MSPIKE_H2 0.001 Average reputation (+2) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: K2YGOBC3THJWH4PLYGKFM3MKXAO47D55 X-Message-ID-Hash: K2YGOBC3THJWH4PLYGKFM3MKXAO47D55 X-MailFrom: d.rusovac@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Add feature-gated modules to evaluate several statically dispatched variants of TOPSIS-based static resource scheduling. The 'lab' feature ought to be activated during tests that involve variants of TOPSIS-based static resource scheduling. Signed-off-by: Dominik Rusovac --- proxmox-resource-scheduling/Cargo.toml | 3 ++ proxmox-resource-scheduling/src/pve_static.rs | 44 +++++++++++++++++ proxmox-resource-scheduling/src/topsis.rs | 48 +++++++++++++++++++ 3 files changed, 95 insertions(+) diff --git a/proxmox-resource-scheduling/Cargo.toml b/proxmox-resource-scheduling/Cargo.toml index a73d8884..5060fae3 100644 --- a/proxmox-resource-scheduling/Cargo.toml +++ b/proxmox-resource-scheduling/Cargo.toml @@ -11,3 +11,6 @@ exclude.workspace = true [dependencies] anyhow.workspace = true serde = { workspace = true, features = [ "derive" ] } + +[features] +lab = [] diff --git a/proxmox-resource-scheduling/src/pve_static.rs b/proxmox-resource-scheduling/src/pve_static.rs index b81086dd..0afbec05 100644 --- a/proxmox-resource-scheduling/src/pve_static.rs +++ b/proxmox-resource-scheduling/src/pve_static.rs @@ -132,3 +132,47 @@ pub fn score_nodes_to_start_service>( .map(|(n, score)| (nodes[n].as_ref().name.clone(), score)) .collect()) } + +#[cfg(feature = "lab")] +pub mod evaluate { + use crate::{ + pve_static::score_nodes_to_start_service, + topsis::evaluate::{score_alternatives_with_variant, DispatchedTopsis}, + }; + + use super::{StaticNodeUsage, StaticServiceUsage, N_CRITERIA, PVE_HA_TOPSIS_CRITERIA}; + + /// Dispatched parts of static resource scheduling + pub trait DispatchedStaticResourceScheduler { + /// The method to turn the stats of `nodes` and `service` into alternatives + fn preprocess>( + &self, + nodes: &[T], + service: &StaticServiceUsage, + ) -> Vec<[f64; N_CRITERIA]>; + } + + /// Score `nodes` using specific `topsis_variant` and `static_resource_scheduling_variant`. + /// + /// Calls [`crate::topsis::score_nodes_to_start_service`] if `static_resource_scheduling_variant` is [`None`] + pub fn score_nodes_to_start_service_with_variant>( + nodes: &[T], + service: &StaticServiceUsage, + topsis_variant: Option<&impl DispatchedTopsis>, + static_resource_scheduling_variant: Option<&impl DispatchedStaticResourceScheduler>, + ) -> Vec<(String, f64)> { + match static_resource_scheduling_variant { + Some(static_resource_scheduling) => score_alternatives_with_variant( + topsis_variant, + static_resource_scheduling.preprocess(nodes, service), + &PVE_HA_TOPSIS_CRITERIA, + ) + .into_iter() + .enumerate() + .map(|(n, score)| (nodes[n].as_ref().name.clone(), score)) + .collect(), + _ => score_nodes_to_start_service(nodes, service) + .unwrap_or_else(|err| panic!("scoring nodes to start service failed: {err}")), + } + } +} diff --git a/proxmox-resource-scheduling/src/topsis.rs b/proxmox-resource-scheduling/src/topsis.rs index 6d078aa6..f52ee27d 100644 --- a/proxmox-resource-scheduling/src/topsis.rs +++ b/proxmox-resource-scheduling/src/topsis.rs @@ -245,3 +245,51 @@ macro_rules! criteria_struct { } }; } + +#[cfg(feature = "lab")] +pub mod evaluate { + use super::{score_alternatives, Criteria, IdealAlternatives, Matrix}; + + /// Dispatched parts of TOPSIS algorithm + pub trait DispatchedTopsis { + /// The method to normalize `alternatives` + fn normalize(&self, alternatives: &mut Matrix); + + /// The method to compute the designated distance of `alternative` to `ideals` + #[allow(private_interfaces)] + fn distance( + &self, + alternative: &[f64; N], + criteria: &Criteria, + ideals: &IdealAlternatives, + ) -> f64; + } + + /// Score alternatives with specific dispatched `topsis_variant`. + /// + /// Calls [`crate::topsis::score_alternatives`] if `topsis_variant` is [`None`] + pub fn score_alternatives_with_variant( + topsis_variant: Option<&impl DispatchedTopsis>, + instance: Vec<[f64; N]>, + criteria: &Criteria, + ) -> Vec { + match topsis_variant { + Some(topsis) => { + let mut alternatives = Matrix(instance); + + topsis.normalize(&mut alternatives); + + let ideals = IdealAlternatives::compute(&alternatives, criteria); + + alternatives + .0 + .iter() + .map(|alternative| topsis.distance(alternative, criteria, &ideals)) + .collect() + } + _ => Matrix::new(instance) + .and_then(|matrix| score_alternatives(&matrix, criteria)) + .unwrap_or_else(|err| panic!("scoring alternatives failed: {err}")), + } + } +} -- 2.47.3