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 A53DB1FF0B6 for ; Thu, 12 Nov 2026 17:34:00 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 8367321882; Thu, 12 Nov 2026 17:32:18 +0100 (CET) From: Daniel Kral To: pve-devel@lists.proxmox.com Subject: [PATCH ha-manager v2 16/16] lrm: prune stale LRM results once per work iteration Date: Thu, 12 Nov 2026 17:31:15 +0100 Message-ID: <20261112163113.294302-19-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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794501128520 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.602 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: 6LDRAGINOA26QJEIZWEYSDAWJU7LXJVK X-Message-ID-Hash: 6LDRAGINOA26QJEIZWEYSDAWJU7LXJVK 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: resource_command_finished() writes only LRM results to $self->{results}, whose HA resource command uid is still active in the current LRM round, i.e., are in $self->{service_status_uids}. Therefore, the only other reason for stale LRM results in $self->{results} is because updates to $self->{service_status} and therefore $self->{service_status_uids} made these become stale. As both $self->{service_status} and $self->{service_status_uids} are only updated in update_lrm_status(), pruning these stale LRM results is only necessary whenever these change. This makes the LRM results exposed in the lrm_status file be pruned more often, which only happened before when the LRM was restarted or resource_command_finished() was called. A test startup of 768 HA resources on a single node at the same time showed a ~21.8x speedup for resource_command_finished(). +---------------------------+---------------+--------------+ | Subroutine | Before Change | After Change | +---------------------------+---------------+--------------+ | check_active_workers | 4.09ms | 998µs | | resource_command_finished | 1.09ms | 50µs | +---------------------------+---------------+--------------+ 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 | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/PVE/HA/LRM.pm b/src/PVE/HA/LRM.pm index 28a1fd56..4fcabbb0 100644 --- a/src/PVE/HA/LRM.pm +++ b/src/PVE/HA/LRM.pm @@ -240,6 +240,11 @@ sub update_lrm_status { $self->{service_status_uids}->{$uid} = 1; } + # prune results which became stale since the last update + for my $uid (keys $self->{results}->%*) { + delete $self->{results}->{$uid} if !$self->{service_status_uids}->{$uid}; + } + my $nodename = $haenv->nodename(); $self->{node_status} = $ms->{node_status}->{$nodename} || 'unknown'; @@ -912,13 +917,6 @@ sub resource_command_finished { state => $w->{state}, exit_code => $exit_code, }; - - my $results = {}; - foreach my $id (keys %{ $self->{results} }) { - next if !$self->{service_status_uids}->{$id}; - $results->{$id} = $self->{results}->{$id}; - } - $self->{results} = $results; } # processes the exit code from a finished resource agent, so that the CRM knows -- 2.47.3