public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox-resource-scheduling 1/2] pve ha: fix scoring issue when a node is overcommitted compared to others
Date: Tue, 21 Mar 2023 13:33:42 +0100	[thread overview]
Message-ID: <20230321123345.128141-2-f.ebner@proxmox.com> (raw)
In-Reply-To: <20230321123345.128141-1-f.ebner@proxmox.com>

When nodes have different stats, the sum of percentage values will be
different for different alternatives, so the linear average is enough.
But when nodes have the same stats, this is not the case, the sum will
be the same, thus the average won't influence the scoring. If there is
an already overcommitted node, all alternatives besides the already
overcommitted node would be scored the same.

To fix it, use the squares of percentages instead, where more evenly
distributed usage across nodes will lead to a smaller value and thus
better scoring.

It's not really necessary to divide by length or take the sqrt, but it
seemed nicer to have something that would give 1.0 if all inputs are
1.0.

Reported-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---

Sorry about the stupid mistake :(

 src/pve_static.rs | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/pve_static.rs b/src/pve_static.rs
index 345c0a2..6663b70 100644
--- a/src/pve_static.rs
+++ b/src/pve_static.rs
@@ -79,11 +79,11 @@ pub fn score_nodes_to_start_service(
         .iter()
         .enumerate()
         .map(|(target_index, _)| {
-            // all of these are as percentages to be comparable across nodes
+            // Base values on percentages to allow comparing nodes with different stats.
             let mut highest_cpu = 0.0;
-            let mut sum_cpu = 0.0;
+            let mut squares_cpu = 0.0;
             let mut highest_mem = 0.0;
-            let mut sum_mem = 0.0;
+            let mut squares_mem = 0.0;
 
             for (index, node) in nodes.iter().enumerate() {
                 let new_cpu = if index == target_index {
@@ -92,7 +92,7 @@ pub fn score_nodes_to_start_service(
                     node.cpu
                 } / (node.maxcpu as f64);
                 highest_cpu = f64::max(highest_cpu, new_cpu);
-                sum_cpu += new_cpu;
+                squares_cpu += new_cpu.powi(2);
 
                 let new_mem = if index == target_index {
                     node.mem + service.maxmem
@@ -101,13 +101,13 @@ pub fn score_nodes_to_start_service(
                 } as f64
                     / node.maxmem as f64;
                 highest_mem = f64::max(highest_mem, new_mem);
-                sum_mem += new_mem;
+                squares_mem += new_mem.powi(2);
             }
 
             PveTopsisAlternative {
-                average_cpu: sum_cpu / len as f64,
+                average_cpu: (squares_cpu / len as f64).sqrt(),
                 highest_cpu,
-                average_memory: sum_mem / len as f64,
+                average_memory: (squares_mem / len as f64).sqrt(),
                 highest_memory: highest_mem,
             }
             .into()
-- 
2.30.2





  reply	other threads:[~2023-03-21 12:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-21 12:33 [pve-devel] [PATCH-SERIES proxmox-{resource-scheduling, perl-rs}] fix scoring issue with overcommitted node Fiona Ebner
2023-03-21 12:33 ` Fiona Ebner [this message]
2023-03-21 12:33 ` [pve-devel] [PATCH proxmox-resource-scheduling 2/2] pve ha: fix typo in comment Fiona Ebner
2023-03-21 12:33 ` [pve-devel] [PATCH proxmox-perl-rs 1/2] pve: test: resource scheduling: use dedicated functions for tests Fiona Ebner
2023-03-21 12:33 ` [pve-devel] [PATCH proxmox-perl-rs 2/2] pve: test: resource scheduling: add test with overcommitted node Fiona Ebner
2023-03-21 14:25 ` [pve-devel] applied-series: [PATCH-SERIES proxmox-{resource-scheduling, perl-rs}] fix scoring issue " Thomas Lamprecht

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=20230321123345.128141-2-f.ebner@proxmox.com \
    --to=f.ebner@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