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 89F371FF0B6 for ; Thu, 12 Nov 2026 17:34:11 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 19E26218A7; Thu, 12 Nov 2026 17:32:19 +0100 (CET) From: Daniel Kral To: pve-devel@lists.proxmox.com Subject: [PATCH ha-manager v2 14/16] lrm: compute valid service uids hash set once per work iteration Date: Thu, 12 Nov 2026 17:31:13 +0100 Message-ID: <20261112163113.294302-17-d.kral@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261112163113.294302-3-d.kral@proxmox.com> References: <20261112163113.294302-3-d.kral@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794501128364 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.598 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: P6RM3AXZD4ESWO6GJS3SP5NGB3KA5JJ5 X-Message-ID-Hash: P6RM3AXZD4ESWO6GJS3SP5NGB3KA5JJ5 X-MailFrom: d.kral@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: $self->{service_status} is only updated in update_lrm_status(), which makes the recomputation of valid HA resource command uids in every invocation of resource_command_finished() unnecessary. A test startup of 768 HA resources on a single node at the same time showed a ~2.5x speedup for resource_command_finished(). +---------------------------+---------------+--------------+ | Subroutine | Before Change | After Change | +---------------------------+---------------+--------------+ | check_active_workers | 11.6ms | 4.09ms | | resource_command_finished | 2.81ms | 1.09ms | +---------------------------+---------------+--------------+ The profiling was done on a physical host with Devel::NYTProf 6.14 [0]. [0] https://metacpan.org/pod/Devel::NYTProf Signed-off-by: Daniel Kral --- src/PVE/HA/LRM.pm | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/PVE/HA/LRM.pm b/src/PVE/HA/LRM.pm index 3dbb8ec4..91a3e1b9 100644 --- a/src/PVE/HA/LRM.pm +++ b/src/PVE/HA/LRM.pm @@ -47,6 +47,8 @@ sub new { # service_status from manager_status in current work() iteration # does contain all HA resources, users must filter for the assigned node service_status => {}, + # Valid service_status UID cache in current work() iteration + service_status_uids => {}, # node_status from manager_status in current work() iteration # this is only used to check whether a fence for the node is requested # see $PVE::HA::NodeStatus::valid_node_states for possible values @@ -232,6 +234,12 @@ sub update_lrm_status { return undef; } else { $self->{service_status} = $ms->{service_status} || {}; + $self->{service_status_uids} = {}; + for my $sd (values $self->{service_status}->%*) { + my $uid = $sd->{uid} or next; + $self->{service_status_uids}->{$uid} = 1; + } + my $nodename = $haenv->nodename(); $self->{node_status} = $ms->{node_status}->{$nodename} || 'unknown'; @@ -902,19 +910,9 @@ sub resource_command_finished { exit_code => $exit_code, }; - my $ss = $self->{service_status}; - - # compute hash of valid/existing uids - my $valid_uids = {}; - foreach my $sid (keys %$ss) { - my $sd = $ss->{$sid}; - next if !$sd->{uid}; - $valid_uids->{ $sd->{uid} } = 1; - } - my $results = {}; foreach my $id (keys %{ $self->{results} }) { - next if !$valid_uids->{$id}; + next if !$self->{service_status_uids}->{$id}; $results->{$id} = $self->{results}->{$id}; } $self->{results} = $results; -- 2.47.3