all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server 3/8] partially fix #7854: block job: monitor: handle completion faster to benefit migration
Date: Thu, 30 Jul 2026 15:15:52 +0200	[thread overview]
Message-ID: <20260730131613.157722-4-f.ebner@proxmox.com> (raw)
In-Reply-To: <20260730131613.157722-1-f.ebner@proxmox.com>

Currently, the block job monitor always sleeps a full second between
iterations. This causes a longer guest downtime for migration that
does offline storage migration. Optimize this, by skipping sleep
directly after issuing the completion commands and by sleeping only
for 0.1 seconds when all jobs are ready. Except when a QMP completion
command fails with 'cannot be completed', sleep for a full second
again.

>From some quick testing with a VM with four disks, the time window
between completing state migration and issuing resume on the target
side shrank from ~2.5 to 1.6 seconds.

A further optimization will be to avoid spawning qm via SSH for the
nbdstop command, and instead re-using the tunnel. This requires some
kind of capability check though, to know if the target side already
supports it.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/QemuServer/BlockJob.pm | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/PVE/QemuServer/BlockJob.pm b/src/PVE/QemuServer/BlockJob.pm
index 0a51a65b..3c8de3e4 100644
--- a/src/PVE/QemuServer/BlockJob.pm
+++ b/src/PVE/QemuServer/BlockJob.pm
@@ -5,6 +5,7 @@ use warnings;
 
 use JSON;
 use Storable qw(dclone);
+use Time::HiRes qw(usleep);
 
 use PVE::Format qw(render_duration render_bytes);
 use PVE::RESTEnvironment qw(log_warn);
@@ -110,6 +111,7 @@ sub monitor {
             }
 
             my $readycounter = 0;
+            my $wait_time = 1_000_000; # microseconds
 
             for my $job_id (sort keys %$jobs) {
                 my $job = $running_jobs->{$job_id};
@@ -161,6 +163,8 @@ sub monitor {
             last if scalar(keys %$jobs) == 0;
 
             if ($readycounter == scalar(keys %$jobs)) {
+                $wait_time = 100_000; # everything is ready, query more often
+
                 if (!$ready_message_printed) {
                     print "all '$op' jobs are ready\n";
                     $ready_message_printed = 1;
@@ -202,6 +206,8 @@ sub monitor {
                     for my $job_id (sort keys %$jobs) {
                         next if $jobs->{$job_id}->{complete};
 
+                        my $got_completion_error;
+
                         # try to switch the disk if source and destination are on the same guest
                         print "$job_id: Completing block job...\n";
 
@@ -225,6 +231,9 @@ sub monitor {
                         if ($err && $err =~ m/cannot be completed/) {
                             print "$job_id: block job cannot be completed, trying again.\n";
                             $err_complete++;
+
+                            $wait_time = 1_000_000; # give it some time
+                            $got_completion_error = 1;
                         } elsif ($err) {
                             die "$job_id: block job cannot be completed - $err\n";
                         } else {
@@ -233,11 +242,14 @@ sub monitor {
 
                             print "$job_id: Completed successfully.\n";
                             $jobs->{$job_id}->{complete} = 1;
+
+                            # query right away, except if there was a completion error
+                            $wait_time = 0 if !$got_completion_error;
                         }
                     }
                 }
             }
-            sleep 1;
+            usleep($wait_time) if $wait_time;
         }
     };
     my $err = $@;
-- 
2.47.3





  parent reply	other threads:[~2026-07-30 13:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30 13:15 [PATCH-SERIES qemu-server 0/8] block job: monitor: improve completion handling and style Fiona Ebner
2026-07-30 13:15 ` [PATCH qemu-server 1/8] block job: monitor: avoid duplicate completion Fiona Ebner
2026-07-30 13:15 ` [PATCH qemu-server 2/8] block job: monitor: only print message that jobs are ready once Fiona Ebner
2026-07-30 13:15 ` Fiona Ebner [this message]
2026-07-30 13:15 ` [PATCH qemu-server 4/8] block job: monitor: factor out job status printing Fiona Ebner
2026-07-30 13:15 ` [PATCH qemu-server 5/8] block job: monitor: make operation argument non-optional Fiona Ebner
2026-07-30 13:15 ` [PATCH qemu-server 6/8] block job: monitor: rename 'op' argument to 'operation' Fiona Ebner
2026-07-30 13:15 ` [PATCH qemu-server 7/8] block job: monitor: pass options as a hash Fiona Ebner
2026-07-30 13:15 ` [PATCH qemu-server 8/8] block job: monitor: properly document function Fiona Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260730131613.157722-4-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal