public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Rusovac <d.rusovac@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH proxmox-perl-rs 06/15] fix #7993: pve-rs: resource-scheduling: add weights to pve bindings
Date: Wed, 21 Oct 2026 10:59:23 +0200	[thread overview]
Message-ID: <20261021085932.1196302-7-d.rusovac@proxmox.com> (raw)
In-Reply-To: <20261021085932.1196302-1-d.rusovac@proxmox.com>

Add weights for weighted load balancing.

Adjust existing resource scheduling test to explicitly use same weights
as before.

Signed-off-by: Dominik Rusovac <d.rusovac@proxmox.com>
---
 .../resource_scheduling/pve_dynamic.rs        | 27 +++++++++++++++----
 .../resource_scheduling/pve_static.rs         | 25 +++++++++++++----
 pve-rs/test/resource_scheduling.pl            |  3 ++-
 3 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/pve-rs/src/bindings/resource_scheduling/pve_dynamic.rs b/pve-rs/src/bindings/resource_scheduling/pve_dynamic.rs
index 8e066e0..d6b6f9b 100644
--- a/pve-rs/src/bindings/resource_scheduling/pve_dynamic.rs
+++ b/pve-rs/src/bindings/resource_scheduling/pve_dynamic.rs
@@ -166,10 +166,16 @@ pub mod pve_rs_resource_scheduling_dynamic {
     ///
     /// See [`proxmox_resource_scheduling::scheduler::Scheduler::node_imbalance`].
     #[export]
-    pub fn calculate_node_imbalance(#[try_from_ref] this: &Scheduler) -> f64 {
+    pub fn calculate_node_imbalance(
+        #[try_from_ref] this: &Scheduler,
+        cpu_weight: usize,
+        mem_weight: usize,
+    ) -> f64 {
         let usage = this.inner.lock().unwrap();
 
-        usage.to_scheduler::<IdentityAggregator>().node_imbalance()
+        usage
+            .to_scheduler::<IdentityAggregator>()
+            .node_imbalance(cpu_weight as f64, mem_weight as f64)
     }
 
     /// Method: Scores the given migration `candidates` by the best node imbalance improvement with
@@ -181,6 +187,8 @@ pub mod pve_rs_resource_scheduling_dynamic {
         #[try_from_ref] this: &Scheduler,
         candidates: Vec<CompactMigrationCandidate>,
         limit: usize,
+        cpu_weight: usize,
+        mem_weight: usize,
     ) -> Result<Vec<ScoredMigration>, Error> {
         let usage = this.inner.lock().unwrap();
 
@@ -188,7 +196,7 @@ pub mod pve_rs_resource_scheduling_dynamic {
 
         Ok(usage
             .to_scheduler::<IdentityAggregator>()
-            .score_best_balancing_migration_candidates(candidates, limit))
+            .score_best_balancing_migration_candidates(candidates, limit, cpu_weight, mem_weight))
     }
 
     /// Method: Scores the given migration `candidates` by the best node imbalance improvement with
@@ -200,6 +208,8 @@ pub mod pve_rs_resource_scheduling_dynamic {
         #[try_from_ref] this: &Scheduler,
         candidates: Vec<CompactMigrationCandidate>,
         limit: usize,
+        cpu_weight: usize,
+        mem_weight: usize,
     ) -> Result<Vec<ScoredMigration>, Error> {
         let usage = this.inner.lock().unwrap();
 
@@ -207,7 +217,12 @@ pub mod pve_rs_resource_scheduling_dynamic {
 
         usage
             .to_scheduler::<IdentityAggregator>()
-            .score_best_balancing_migration_candidates_topsis(&candidates, limit)
+            .score_best_balancing_migration_candidates_topsis(
+                &candidates,
+                limit,
+                cpu_weight,
+                mem_weight,
+            )
     }
 
     /// Method: Scores nodes to start a resource with the usage statistics `resource_stats` on.
@@ -217,11 +232,13 @@ pub mod pve_rs_resource_scheduling_dynamic {
     pub fn score_nodes_to_start_resource(
         #[try_from_ref] this: &Scheduler,
         resource_stats: DynamicResourceStats,
+        cpu_weight: usize,
+        mem_weight: usize,
     ) -> Result<Vec<(String, f64)>, Error> {
         let usage = this.inner.lock().unwrap();
 
         usage
             .to_scheduler::<StartingAsStartedResourceAggregator>()
-            .score_nodes_to_start_resource(resource_stats)
+            .score_nodes_to_start_resource(resource_stats, cpu_weight, mem_weight)
     }
 }
diff --git a/pve-rs/src/bindings/resource_scheduling/pve_static.rs b/pve-rs/src/bindings/resource_scheduling/pve_static.rs
index d83aa38..2fa8d8c 100644
--- a/pve-rs/src/bindings/resource_scheduling/pve_static.rs
+++ b/pve-rs/src/bindings/resource_scheduling/pve_static.rs
@@ -162,12 +162,16 @@ pub mod pve_rs_resource_scheduling_static {
     ///
     /// See [`proxmox_resource_scheduling::scheduler::Scheduler::node_imbalance`].
     #[export]
-    pub fn calculate_node_imbalance(#[try_from_ref] this: &Scheduler) -> f64 {
+    pub fn calculate_node_imbalance(
+        #[try_from_ref] this: &Scheduler,
+        cpu_weight: usize,
+        mem_weight: usize,
+    ) -> f64 {
         let usage = this.inner.lock().unwrap();
 
         usage
             .to_scheduler::<StartedResourceAggregator>()
-            .node_imbalance()
+            .node_imbalance(cpu_weight as f64, mem_weight as f64)
     }
 
     /// Method: Scores the given migration `candidates` by the best node imbalance improvement with
@@ -179,6 +183,8 @@ pub mod pve_rs_resource_scheduling_static {
         #[try_from_ref] this: &Scheduler,
         candidates: Vec<CompactMigrationCandidate>,
         limit: usize,
+        cpu_weight: usize,
+        mem_weight: usize,
     ) -> Result<Vec<ScoredMigration>, Error> {
         let usage = this.inner.lock().unwrap();
 
@@ -186,7 +192,7 @@ pub mod pve_rs_resource_scheduling_static {
 
         Ok(usage
             .to_scheduler::<StartedResourceAggregator>()
-            .score_best_balancing_migration_candidates(candidates, limit))
+            .score_best_balancing_migration_candidates(candidates, limit, cpu_weight, mem_weight))
     }
 
     /// Method: Scores the given migration `candidates` by the best node imbalance improvement with
@@ -198,6 +204,8 @@ pub mod pve_rs_resource_scheduling_static {
         #[try_from_ref] this: &Scheduler,
         candidates: Vec<CompactMigrationCandidate>,
         limit: usize,
+        cpu_weight: usize,
+        mem_weight: usize,
     ) -> Result<Vec<ScoredMigration>, Error> {
         let usage = this.inner.lock().unwrap();
 
@@ -205,7 +213,12 @@ pub mod pve_rs_resource_scheduling_static {
 
         usage
             .to_scheduler::<StartedResourceAggregator>()
-            .score_best_balancing_migration_candidates_topsis(&candidates, limit)
+            .score_best_balancing_migration_candidates_topsis(
+                &candidates,
+                limit,
+                cpu_weight,
+                mem_weight,
+            )
     }
 
     /// Method: Scores nodes to start a service with the usage statistics `service_stats` on.
@@ -215,11 +228,13 @@ pub mod pve_rs_resource_scheduling_static {
     pub fn score_nodes_to_start_service(
         #[try_from_ref] this: &Scheduler,
         service_stats: StaticResourceStats,
+        cpu_weight: usize,
+        mem_weight: usize,
     ) -> Result<Vec<(String, f64)>, Error> {
         let usage = this.inner.lock().unwrap();
 
         usage
             .to_scheduler::<StartedResourceAggregator>()
-            .score_nodes_to_start_resource(service_stats)
+            .score_nodes_to_start_resource(service_stats, cpu_weight, mem_weight)
     }
 }
diff --git a/pve-rs/test/resource_scheduling.pl b/pve-rs/test/resource_scheduling.pl
index 3775242..31f2622 100755
--- a/pve-rs/test/resource_scheduling.pl
+++ b/pve-rs/test/resource_scheduling.pl
@@ -11,7 +11,8 @@ use PVE::RS::ResourceScheduling::Dynamic;
 my sub score_nodes {
     my ($static, $service) = @_;
 
-    my $score_list = $static->score_nodes_to_start_service($service);
+    # uses original empirically determined weights
+    my $score_list = $static->score_nodes_to_start_service($service, 1.0, 5.0);
 
     # imitate HA manager
     my $scores = { map { $_->[0] => -$_->[1] } $score_list->@* };
-- 
2.47.3





  parent reply	other threads:[~2026-10-21  9:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21  8:59 [RFC PATCH-SERIES cluster/ha-manager/manager/proxmox{,-perl-rs} 00/15] fix #7993: implement weighted auto rebalancing Dominik Rusovac
2026-10-21  8:59 ` [PATCH proxmox 01/15] resource-scheduling: scheduler: fix typos Dominik Rusovac
2026-10-21  8:59 ` [PATCH proxmox 02/15] resource-scheduling: scheduler: abstract post-migration stats logic Dominik Rusovac
2026-10-21 12:49   ` Daniel Kral
2026-10-21  8:59 ` [PATCH proxmox 03/15] fix #7993: resource-scheduling: lift to weighted load balancing Dominik Rusovac
2026-10-21  8:59 ` [PATCH proxmox 04/15] workspace,resource-scheduling: add proptest crate Dominik Rusovac
2026-10-21  8:59 ` [PATCH proxmox 05/15] resource-scheduling: scheduler: proptest weights Dominik Rusovac
2026-10-21  8:59 ` Dominik Rusovac [this message]
2026-10-21  8:59 ` [PATCH pve-manager 07/15] fix #7993: ui: form: crs options: add weights Dominik Rusovac
2026-10-21  8:59 ` [PATCH pve-manager 08/15] ui: form: crs options: make options advanced Dominik Rusovac
2026-10-21  8:59 ` [PATCH pve-ha-manager 09/15] manager: remove obsolete argument Dominik Rusovac
2026-10-21  8:59 ` [PATCH pve-ha-manager 10/15] fix #7993: manager,usage: implement weighted auto rebalancing Dominik Rusovac
2026-10-21  8:59 ` [PATCH pve-ha-manager 11/15] sim: hardware: enable datacenter config changes at runtime Dominik Rusovac
2026-10-21  8:59 ` [PATCH pve-ha-manager 12/15] manager: log changes to crs settings Dominik Rusovac
2026-10-21  8:59 ` [PATCH pve-ha-manager 13/15] test: add auto rebalance with weights test cases Dominik Rusovac
2026-10-21  8:59 ` [PATCH pve-ha-manager 14/15] manager: rename update_crs_scheduler_mode Dominik Rusovac
2026-10-21  8:59 ` [PATCH pve-cluster 15/15] fix #7993: datacenter config: add ha-auto-rebalance-{cpu,mem}-weight Dominik Rusovac

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261021085932.1196302-7-d.rusovac@proxmox.com \
    --to=d.rusovac@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal