From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 3EBE0954E6 for ; Mon, 26 Feb 2024 17:51:49 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 17310131CF for ; Mon, 26 Feb 2024 17:51:19 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Mon, 26 Feb 2024 17:51:18 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id C58D4473BC for ; Mon, 26 Feb 2024 17:51:17 +0100 (CET) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Mon, 26 Feb 2024 17:50:43 +0100 Message-ID: <20240226165052.1219597-1-c.heiss@proxmox.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.005 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH installer] sys: command: wait for process exit with sub-second granularity X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Feb 2024 16:51:49 -0000 Using full seconds as a granularity for sleeping between waitpid()'s is way too much and unnecessarily slows down the installation a lot. Most processes take a few moments after closing their stdin/stdout to actually exit fully, which means that we would sleep a second in most cases. Lower it to 0.1 second, which immensely improves the situation. Some values for comparison; tui-installer on the same bog-standard 2-core, SeaBIOS, ext4, virtio VM (roughly averaged over multiple runs): * 8.0 ISO (baseline): ~2:30 min * w/o patch: ~9:00 min * w/ patch: ~2:30 min Values measured are from pressing the 'Install' button until the autoreboot dialog (aka. install finished) popped up. Fixes: 152bbef ("sys: command: factor out kill() + waitpid() from run_command()") Reported-by: Stoiko Ivanov Reported-by: Filip Schauer Signed-off-by: Christoph Heiss --- Proxmox/Sys/Command.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Proxmox/Sys/Command.pm b/Proxmox/Sys/Command.pm index ac505c4..d2dcd42 100644 --- a/Proxmox/Sys/Command.pm +++ b/Proxmox/Sys/Command.pm @@ -9,6 +9,7 @@ use IPC::Open3; use IO::Select; use String::ShellQuote; use POSIX ":sys_wait_h"; +use Time::HiRes qw(usleep); use Proxmox::Install::ISOEnv; use Proxmox::Log; @@ -52,12 +53,12 @@ my sub wait_for_process { kill('TERM', $pid) if $params{kill}; - my $timeout = $params{timeout} // 5; + my $timeout = ($params{timeout} // 5) * 10; # waiting 0.1 secs per loop for (0 .. $timeout) { my $terminated = waitpid($pid, WNOHANG); return $? if $terminated > 0; - sleep(1) if $_ != $timeout; # all but last round + usleep(100_000) if $_ != $timeout; # sleep 0.1 sec, on all but last round kill('KILL', $pid) if $params{kill} && $_ == 1; # just first round } -- 2.43.0