From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 2790B1FF065 for ; Mon, 23 Nov 2026 15:00:46 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id A58B12140A; Mon, 23 Nov 2026 15:00:45 +0100 (CET) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 23 Nov 2026 15:00:40 +0100 Message-Id: Subject: Re: [PATCH pve-ha-manager v2 18/19] fix #7993: manager,usage: use weights for static and dynamic mode From: "Dominik Rusovac" To: "Daniel Kral" , X-Mailer: aerc 0.20.0 References: <20261112094437.1951271-1-d.rusovac@proxmox.com> <20261112094437.1951271-19-d.rusovac@proxmox.com> In-Reply-To: X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795442440998 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.022 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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: 5VNRWA3SLKJK34VYPWQJBTNGS4TBELII X-Message-ID-Hash: 5VNRWA3SLKJK34VYPWQJBTNGS4TBELII 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: thx for the review! On Mon Nov 23, 2026 at 1:45 PM CET, Daniel Kral wrote: > On Thu Nov 12, 2026 at 10:44 AM CET, Dominik Rusovac wrote: >> pass the ha-cpu-weight and ha-mem-weight CRS options to the static and >> dynamic scheduler, so that users can prioritize balancing the CPU load >> or the memory usage of nodes. weights apply to the load imbalance, both >> automatic rebalancing methods and the selection of a node to start or >> recover a resource on >> >> without configured weights, the TOPSIS method keeps favoring memory >> usage 5 times over CPU load. if TOPSIS is the automatic rebalancing >> method, pass weights of 1:5 in that case, so that the node imbalance is >> weighted the same way and reflects what the TOPSIS method balances. this >> changes the behavior for existing setups using the TOPSIS method: after >> upgrading, their load imbalance is dominated by memory usage. setups >> using the bruteforce method keep the unweighted load imbalance > > The "this changes the behavior for existing setups..." should come first > here, because this is more the important part, because users essentially > cannot set the weights before upgrading. The rest should go after it. 'pass weights of 1:5 in that case' is not addressed at users and the part before 'this changes existing behavior [...]' is what 'this' refers to, which apparently seems to be misleading or confusing, sorry for that just swapping the order of sentences, however, is even more confusing imo I'll just rewrite the entire paragraph smh, so something along the lines of 'this changes existing behavior [...]' comes first > > I just wonder whether this could cause the load balancer to make wildly > different rebalancing decisions... The only test case that changes below > for the TOPSIS method shows that for that particular test case the > now weighted imbalance value is dampened... But is that true for most > cases so it doesn't cause unwanted behavioral changes after upgrading? > I might be wrong but imo it's hard to make generalizations here I suppose by 'dampened' you refer to the fact that the imbalance value decreased, right? if so, the value is dampened for this very test case, because CPU load alone (1:0) is clearly more imbalanced (0.76) than memory usage (0.42) alone (0:1)=20 hence, weighting memory usage 5 times more than CPU load dampens the imbalance value here I guess 'unwanted behavioral changes after upgrading' can go either way: the imbalance value is *seemingly* too low or to high now... it will most likely not stay the same, but as a matter of fact it can, e.g.: 3 nodes with cpu=3D[0.6, 0.2, 0.1] and mem=3D[0.15,0.35,0.4] where imbalance results in 12.73% for both 1:1 and 1:5, due to the covariance cancellation effect 'seemingly' is the key point here, the imposed changed on how the imbalance computation prioritizes resources can be (A) welcomed, (B) refused or (C) even go unnoticed (if the effect is neglectable). either way, the only thing that's guaranteed is that the weights used are consistent with the weights of criteria used for ranking migration candidates. in other words, the configured weights must consistently play into how we quantify imbalance and how qualify the best migration candidates weighting resources differently when qualifying migration candidates and quantifying load imbalance is not an option; it has to be consistent. so, in case of A or B, re-adjust the weights accordingly. in case of C, there is no problem, anyway, I guess > One thing that comes to my mind, is that the dampened imbalance value in > the default setting for TOPSIS would make the threshold trigger load > balancing migrations later than before, no? > I don't know, what if a cluster is rather memory-heavy than cpu-heavy? [snip] >> diff --git a/src/PVE/HA/Manager.pm b/src/PVE/HA/Manager.pm >> index 7de8781..3db5402 100644 >> --- a/src/PVE/HA/Manager.pm >> +++ b/src/PVE/HA/Manager.pm >> @@ -174,6 +174,39 @@ sub update_crs_settings { >> 0.1, >> ); >> =20 >> + my ($cpu_weight, $mem_weight) =3D $crs_cfg->@{qw(ha-cpu-weight ha-m= em-weight)}; >> + my $weights_configured =3D defined($cpu_weight) || defined($mem_wei= ght); >> + # the legacy TOPSIS criteria favor memory usage 5 times over CPU lo= ad by default, weigh the node >> + # load the same way, so that the imbalance reflects what the TOPSIS= method balances >> + my $use_legacy_topsis_weights =3D !$weights_configured && $auto_reb= alance->{method} eq 'topsis'; >> + >> + $self->update_crs_option('ha-cpu-weight', \$crs->{cpu_weight}, $cpu= _weight, 1); >> + $self->update_crs_option( >> + 'ha-mem-weight', >> + \$crs->{mem_weight}, >> + $mem_weight, >> + $use_legacy_topsis_weights ? 5 : 1, >> + ); >> + >> + my $scheduler_options; >> + my $all_weights_zero =3D 0; >> + if (!$crs->{cpu_weight} && !$crs->{mem_weight}) { >> + # no resource would contribute to the node load, so there is no= thing to balance; keep >> + # the default weights for selecting nodes to start or recover r= esources on >> + $haenv->log( >> + 'warning', >> + "all CRS weights are set to 0, ignoring them and skipping a= utomatic rebalancing", >> + ) if !$crs->{all_weights_zero}; >> + $all_weights_zero =3D 1; >> + } elsif ($weights_configured || $use_legacy_topsis_weights) { >> + $scheduler_options =3D { >> + 'cpu-weight' =3D> $crs->{cpu_weight}, >> + 'mem-weight' =3D> $crs->{mem_weight}, >> + }; >> + } >> + $crs->{scheduler_options} =3D $scheduler_options; >> + $crs->{all_weights_zero} =3D $all_weights_zero; > > nit: the relevant parts should get a > > # FIXME MAJOR VERSION: ... > > because the complexity of holding backwards compatible options here > should be removed then to reduce maintaining unnecessary complexity > here in the future. > ack > Maybe we can even pivot both 'bruteforce' and 'topsis' having 1:1 > weights from the next major version on, so that the behavior is less > complex to explain to (and understand by) new users as well. +1 [snip] >> diff --git a/src/PVE/HA/Usage/Dynamic.pm b/src/PVE/HA/Usage/Dynamic.pm >> index 76d0fea..0da6115 100644 >> --- a/src/PVE/HA/Usage/Dynamic.pm >> +++ b/src/PVE/HA/Usage/Dynamic.pm >> @@ -9,12 +9,14 @@ use PVE::RS::ResourceScheduling::Dynamic; >> use base qw(PVE::HA::Usage); >> =20 >> sub new { >> - my ($class, $haenv, $service_stats) =3D @_; >> + my ($class, $haenv, $service_stats, $scheduler_options) =3D @_; >> =20 >> my $node_stats =3D eval { $haenv->get_dynamic_node_stats() }; >> die "did not get dynamic node usage information - $@" if $@; >> =20 >> - my $scheduler =3D eval { PVE::RS::ResourceScheduling::Dynamic->new(= ) }; >> + # only pass options if there are any, so that older versions of the= bindings still work >> + my @args =3D defined($scheduler_options) ? ($scheduler_options) : (= ); >> + my $scheduler =3D eval { PVE::RS::ResourceScheduling::Dynamic->new(= @args) }; > > nit: could also be dropped in a major version, because the Option<...> > could probably be dropped safely in the future to have less logic > for this here > ack >> die "unable to initialize dynamic scheduling - $@" if $@; >> =20 >> return bless { >> diff --git a/src/PVE/HA/Usage/Static.pm b/src/PVE/HA/Usage/Static.pm >> index e67d5f5..9b91ba6 100644 >> --- a/src/PVE/HA/Usage/Static.pm >> +++ b/src/PVE/HA/Usage/Static.pm >> @@ -9,12 +9,14 @@ use PVE::RS::ResourceScheduling::Static; >> use base qw(PVE::HA::Usage); >> =20 >> sub new { >> - my ($class, $haenv, $service_stats) =3D @_; >> + my ($class, $haenv, $service_stats, $scheduler_options) =3D @_; >> =20 >> my $node_stats =3D eval { $haenv->get_static_node_stats() }; >> die "did not get static node usage information - $@" if $@; >> =20 >> - my $scheduler =3D eval { PVE::RS::ResourceScheduling::Static->new()= ; }; >> + # only pass options if there are any, so that older versions of the= bindings still work >> + my @args =3D defined($scheduler_options) ? ($scheduler_options) : (= ); >> + my $scheduler =3D eval { PVE::RS::ResourceScheduling::Static->new(@= args) }; > > same here > ack [snip]