public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH proxmox-resource-scheduling] pve static: add one to avoid boosting tiny relative differences
@ 2023-03-21 16:44 Fiona Ebner
  2023-03-21 16:44 ` [pve-devel] [PATCH proxmox-perl-rs 1/2] pve: test: resource scheduling: add test where memory is secondary to CPU Fiona Ebner
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Fiona Ebner @ 2023-03-21 16:44 UTC (permalink / raw)
  To: pve-devel

Only the relative difference for values between different alternatives
is relevant, meaning 0.002 vs 0.004 and 0.2 vs 0.4 will influence the
scoring in the same way. This is not really desirable, because values
closer to 1.0 indicate higher load and thus should influence the
scoring more than differences that are actually tiny, but big when
viewed as a relative difference.

To avoid the issue, simply add 1.0 to all values. Like that, 1.002 vs
1.004 will also be small when viewed as a relative difference.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/pve_static.rs | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/pve_static.rs b/src/pve_static.rs
index 814d44f..d39614c 100644
--- a/src/pve_static.rs
+++ b/src/pve_static.rs
@@ -104,11 +104,13 @@ pub fn score_nodes_to_start_service(
                 squares_mem += new_mem.powi(2);
             }
 
+            // Add 1.0 to avoid boosting tiny differences: e.g. 0.004 is twice as much as 0.002, but
+            // 1.004 is only slightly more than 1.002.
             PveTopsisAlternative {
-                average_cpu: (squares_cpu / len as f64).sqrt(),
-                highest_cpu,
-                average_memory: (squares_mem / len as f64).sqrt(),
-                highest_memory: highest_mem,
+                average_cpu: 1.0 + (squares_cpu / len as f64).sqrt(),
+                highest_cpu: 1.0 + highest_cpu,
+                average_memory: 1.0 + (squares_mem / len as f64).sqrt(),
+                highest_memory: 1.0 + highest_mem,
             }
             .into()
         })
-- 
2.30.2





^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pve-devel] [PATCH proxmox-perl-rs 1/2] pve: test: resource scheduling: add test where memory is secondary to CPU
  2023-03-21 16:44 [pve-devel] [PATCH proxmox-resource-scheduling] pve static: add one to avoid boosting tiny relative differences Fiona Ebner
@ 2023-03-21 16:44 ` Fiona Ebner
  2023-03-21 16:44 ` [pve-devel] [PATCH proxmox-perl-rs 2/2] pve: test: resource scheduling: add another " Fiona Ebner
  2023-03-22  8:32 ` [pve-devel] applied: [PATCH proxmox-resource-scheduling] pve static: add one to avoid boosting tiny relative differences Thomas Lamprecht
  2 siblings, 0 replies; 6+ messages in thread
From: Fiona Ebner @ 2023-03-21 16:44 UTC (permalink / raw)
  To: pve-devel

because memory usage differences are small.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 pve-rs/test/resource_scheduling.pl | 46 ++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/pve-rs/test/resource_scheduling.pl b/pve-rs/test/resource_scheduling.pl
index fbedfe1..c6724a4 100755
--- a/pve-rs/test/resource_scheduling.pl
+++ b/pve-rs/test/resource_scheduling.pl
@@ -86,8 +86,54 @@ sub test_overcommitted {
     is($nodes[3], "A", 'fourth should be A');
 }
 
+sub test_balance_small_memory_difference_with_start_load {
+    my $static = PVE::RS::ResourceScheduling::Static->new();
+    # Memory is different to avoid flaky results with what would otherwise be ties.
+    $static->add_node("A", 8, 10_000_000_000);
+    $static->add_node("B", 4, 9_000_000_000);
+    $static->add_node("C", 4, 8_000_000_000);
+
+    $static->add_service_usage_to_node("A", { maxcpu => 4, maxmem => 1_000_000_000 });
+    $static->add_service_usage_to_node("B", { maxcpu => 2, maxmem => 1_000_000_000 });
+    $static->add_service_usage_to_node("C", { maxcpu => 2, maxmem => 1_000_000_000 });
+
+    my $service = {
+	maxcpu => 3,
+	maxmem => 16_000_000,
+    };
+
+    for (my $i = 0; $i < 20; $i++) {
+	my $score_list = $static->score_nodes_to_start_service($service);
+
+	# imitate HA manager
+	my $scores = { map { $_->[0] => -$_->[1] } $score_list->@* };
+	my @nodes = sort {
+	    $scores->{$a} <=> $scores->{$b} || $a cmp $b
+	} keys $scores->%*;
+
+	if ($i % 4 <= 1) {
+	    is($nodes[0], "A", 'first should be A');
+	    is($nodes[1], "B", 'second should be B');
+	    is($nodes[2], "C", 'third should be C');
+	} elsif ($i % 4 == 2) {
+	    is($nodes[0], "B", 'first should be B');
+	    is($nodes[1], "C", 'second should be C');
+	    is($nodes[2], "A", 'third should be A');
+	} elsif ($i % 4 == 3) {
+	    is($nodes[0], "C", 'first should be C');
+	    is($nodes[1], "A", 'second should be A');
+	    is($nodes[2], "B", 'third should be B');
+	} else {
+	    die "internal error, got $i % 4 == " . ($i % 4) . "\n";
+	}
+
+	$static->add_service_usage_to_node($nodes[0], $service);
+    }
+}
+
 test_basic();
 test_balance();
 test_overcommitted();
+test_balance_small_memory_difference_with_start_load();
 
 done_testing();
-- 
2.30.2





^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pve-devel] [PATCH proxmox-perl-rs 2/2] pve: test: resource scheduling: add another test where memory is secondary to CPU
  2023-03-21 16:44 [pve-devel] [PATCH proxmox-resource-scheduling] pve static: add one to avoid boosting tiny relative differences Fiona Ebner
  2023-03-21 16:44 ` [pve-devel] [PATCH proxmox-perl-rs 1/2] pve: test: resource scheduling: add test where memory is secondary to CPU Fiona Ebner
@ 2023-03-21 16:44 ` Fiona Ebner
  2023-03-22  8:32 ` [pve-devel] applied: [PATCH proxmox-resource-scheduling] pve static: add one to avoid boosting tiny relative differences Thomas Lamprecht
  2 siblings, 0 replies; 6+ messages in thread
From: Fiona Ebner @ 2023-03-21 16:44 UTC (permalink / raw)
  To: pve-devel

but this time, without any start load on the node. This test fails
with librust-proxmox-resource-scheduling-dev=0.2.0-1

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 pve-rs/test/resource_scheduling.pl | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/pve-rs/test/resource_scheduling.pl b/pve-rs/test/resource_scheduling.pl
index c6724a4..e3b7d2e 100755
--- a/pve-rs/test/resource_scheduling.pl
+++ b/pve-rs/test/resource_scheduling.pl
@@ -86,16 +86,20 @@ sub test_overcommitted {
     is($nodes[3], "A", 'fourth should be A');
 }
 
-sub test_balance_small_memory_difference_with_start_load {
+sub test_balance_small_memory_difference {
+    my ($with_start_load) = @_;
+
     my $static = PVE::RS::ResourceScheduling::Static->new();
     # Memory is different to avoid flaky results with what would otherwise be ties.
     $static->add_node("A", 8, 10_000_000_000);
     $static->add_node("B", 4, 9_000_000_000);
     $static->add_node("C", 4, 8_000_000_000);
 
-    $static->add_service_usage_to_node("A", { maxcpu => 4, maxmem => 1_000_000_000 });
-    $static->add_service_usage_to_node("B", { maxcpu => 2, maxmem => 1_000_000_000 });
-    $static->add_service_usage_to_node("C", { maxcpu => 2, maxmem => 1_000_000_000 });
+    if ($with_start_load) {
+	$static->add_service_usage_to_node("A", { maxcpu => 4, maxmem => 1_000_000_000 });
+	$static->add_service_usage_to_node("B", { maxcpu => 2, maxmem => 1_000_000_000 });
+	$static->add_service_usage_to_node("C", { maxcpu => 2, maxmem => 1_000_000_000 });
+    }
 
     my $service = {
 	maxcpu => 3,
@@ -134,6 +138,7 @@ sub test_balance_small_memory_difference_with_start_load {
 test_basic();
 test_balance();
 test_overcommitted();
-test_balance_small_memory_difference_with_start_load();
+test_balance_small_memory_difference(1);
+test_balance_small_memory_difference(0);
 
 done_testing();
-- 
2.30.2





^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pve-devel] applied: [PATCH proxmox-resource-scheduling] pve static: add one to avoid boosting tiny relative differences
  2023-03-21 16:44 [pve-devel] [PATCH proxmox-resource-scheduling] pve static: add one to avoid boosting tiny relative differences Fiona Ebner
  2023-03-21 16:44 ` [pve-devel] [PATCH proxmox-perl-rs 1/2] pve: test: resource scheduling: add test where memory is secondary to CPU Fiona Ebner
  2023-03-21 16:44 ` [pve-devel] [PATCH proxmox-perl-rs 2/2] pve: test: resource scheduling: add another " Fiona Ebner
@ 2023-03-22  8:32 ` Thomas Lamprecht
  2023-10-05  9:50   ` Fiona Ebner
  2 siblings, 1 reply; 6+ messages in thread
From: Thomas Lamprecht @ 2023-03-22  8:32 UTC (permalink / raw)
  To: Proxmox VE development discussion, Fiona Ebner

Am 21/03/2023 um 17:44 schrieb Fiona Ebner:
> Only the relative difference for values between different alternatives
> is relevant, meaning 0.002 vs 0.004 and 0.2 vs 0.4 will influence the
> scoring in the same way. This is not really desirable, because values
> closer to 1.0 indicate higher load and thus should influence the
> scoring more than differences that are actually tiny, but big when
> viewed as a relative difference.
> 
> To avoid the issue, simply add 1.0 to all values. Like that, 1.002 vs
> 1.004 will also be small when viewed as a relative difference.
> 
> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
> ---
>  src/pve_static.rs | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
>

applied series (yesterday already), thanks!




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [pve-devel] applied: [PATCH proxmox-resource-scheduling] pve static: add one to avoid boosting tiny relative differences
  2023-03-22  8:32 ` [pve-devel] applied: [PATCH proxmox-resource-scheduling] pve static: add one to avoid boosting tiny relative differences Thomas Lamprecht
@ 2023-10-05  9:50   ` Fiona Ebner
  2023-11-06 17:21     ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 6+ messages in thread
From: Fiona Ebner @ 2023-10-05  9:50 UTC (permalink / raw)
  To: Thomas Lamprecht, Proxmox VE development discussion

Am 22.03.23 um 09:32 schrieb Thomas Lamprecht:
> Am 21/03/2023 um 17:44 schrieb Fiona Ebner:
>> Only the relative difference for values between different alternatives
>> is relevant, meaning 0.002 vs 0.004 and 0.2 vs 0.4 will influence the
>> scoring in the same way. This is not really desirable, because values
>> closer to 1.0 indicate higher load and thus should influence the
>> scoring more than differences that are actually tiny, but big when
>> viewed as a relative difference.
>>
>> To avoid the issue, simply add 1.0 to all values. Like that, 1.002 vs
>> 1.004 will also be small when viewed as a relative difference.
>>
>> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
>> ---
>>  src/pve_static.rs | 10 ++++++----
>>  1 file changed, 6 insertions(+), 4 deletions(-)
>>
>>
> 
> applied series (yesterday already), thanks!

Seems like only this single patch was applied, I don't see
proxmox-perl-rs ones there (still apply cleanly).




^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pve-devel] applied: applied: [PATCH proxmox-resource-scheduling] pve static: add one to avoid boosting tiny relative differences
  2023-10-05  9:50   ` Fiona Ebner
@ 2023-11-06 17:21     ` Thomas Lamprecht
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Lamprecht @ 2023-11-06 17:21 UTC (permalink / raw)
  To: Proxmox VE development discussion, Fiona Ebner

Am 05/10/2023 um 11:50 schrieb Fiona Ebner:
> Seems like only this single patch was applied, I don't see
> proxmox-perl-rs ones there (still apply cleanly).

you're right, applied now, thanks (for the patch and the reminder)!




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-11-06 17:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-21 16:44 [pve-devel] [PATCH proxmox-resource-scheduling] pve static: add one to avoid boosting tiny relative differences Fiona Ebner
2023-03-21 16:44 ` [pve-devel] [PATCH proxmox-perl-rs 1/2] pve: test: resource scheduling: add test where memory is secondary to CPU Fiona Ebner
2023-03-21 16:44 ` [pve-devel] [PATCH proxmox-perl-rs 2/2] pve: test: resource scheduling: add another " Fiona Ebner
2023-03-22  8:32 ` [pve-devel] applied: [PATCH proxmox-resource-scheduling] pve static: add one to avoid boosting tiny relative differences Thomas Lamprecht
2023-10-05  9:50   ` Fiona Ebner
2023-11-06 17:21     ` [pve-devel] applied: " Thomas Lamprecht

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