[pve-devel] [PATCH] - fix setting migration parameters

Alexandre Derumier aderumier at odiso.com
Thu Dec 27 06:45:21 CET 2012


From: Stefan Priebe <s.priebe at profihost.ag>

 - move migration speed/downtime from QemuServer vm_start to
   QemuMigrate phase2
 - lower default migration downtime value to 0

changelog by aderumier

 - remove default value of 1s for migrate_downtime
 - add logs downtime and expected downtime migration stats
 - only send qmp migrate_downtime if migrate_downtime is defined
 - add errors logs on qm start of target vm.
 - cast int() for json values

tested with youtube video playing, no qmp migrate_downtime (default of 30ms), the downtime is around 500-600ms.
---
 PVE/QemuMigrate.pm |   43 +++++++++++++++++++++++++++++++++++--------
 PVE/QemuServer.pm  |   16 ----------------
 2 files changed, 35 insertions(+), 24 deletions(-)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 0711681..dbbeb69 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -312,7 +312,10 @@ sub phase2 {
 	if ($line =~ m/^migration listens on port (\d+)$/) {
 	    $rport = $1;
 	}
-    }, errfunc => sub {});
+    }, errfunc => sub {
+	my $line = shift;
+	print $line."\n";
+    });
 
     die "unable to detect remote migration port\n" if !$rport;
 
@@ -323,24 +326,46 @@ sub phase2 {
     $self->{tunnel} = $self->fork_tunnel($self->{nodeip}, $lport, $rport);
 
     $self->log('info', "starting online/live migration on port $lport");
-    # start migration
 
-    my $start = time();
+    # load_defaults
+    my $defaults = PVE::QemuServer::load_defaults();
+
+    # always set migrate speed (overwrite kvm default of 32m)
+    # we set a very hight default of 8192m which is basically unlimited
+    my $migrate_speed = $defaults->{migrate_speed} || 8192;
+    $migrate_speed = $conf->{migrate_speed} || $migrate_speed;
+    $migrate_speed = $migrate_speed * 1048576;
+    $self->log('info', "migrate_set_speed: $migrate_speed");
+    eval {
+        PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "migrate_set_speed", value => int($migrate_speed));
+    };
+    $self->log('info', "migrate_set_speed error: $@") if $@;
+
+    my $migrate_downtime = $defaults->{migrate_downtime};
+    $migrate_downtime = $conf->{migrate_downtime} if defined($conf->{migrate_downtime});
+    if (defined($migrate_downtime)) {
+	$self->log('info', "migrate_set_downtime: $migrate_downtime");
+	eval {
+	    PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "migrate_set_downtime", value => int($migrate_downtime));
+	};
+	$self->log('info', "migrate_set_downtime error: $@") if $@;
+    }
 
     my $capabilities = {};
     $capabilities->{capability} =  "xbzrle";
     $capabilities->{state} = JSON::false;
-
     eval {
 	PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "migrate-set-capabilities", capabilities => [$capabilities]);
     };
 
-    #set cachesize 10% of the total memory
+    # set cachesize 10% of the total memory
     my $cachesize = int($conf->{memory}*1048576/10);
     eval {
 	PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "migrate-set-cache-size", value => $cachesize);
     };
 
+    # start migration
+    my $start = time();
     eval {
         PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "migrate", uri => "tcp:localhost:$lport");
     };
@@ -353,7 +378,6 @@ sub phase2 {
     while (1) {
 	$i++;
 	my $avglstat = $lstat/$i if $lstat;
-
 	usleep($usleep);
 	my $stat;
 	eval {
@@ -375,7 +399,8 @@ sub phase2 {
 		my $delay = time() - $start;
 		if ($delay > 0) {
 		    my $mbps = sprintf "%.2f", $conf->{memory}/$delay;
-		    $self->log('info', "migration speed: $mbps MB/s");
+		    $self->log('info', "migration speed: $mbps MB/s - downtime $stat->{downtime} ms");
+			
 		}
 	    }
 
@@ -397,11 +422,13 @@ sub phase2 {
 		my $xbzrlepages = $stat->{"xbzrle-cache"}->{"pages"} || 0;
 		my $xbzrlecachemiss = $stat->{"xbzrle-cache"}->{"cache-miss"} || 0;
 		my $xbzrleoverflow = $stat->{"xbzrle-cache"}->{"overflow"} || 0;
+		my $expected_downtime = $stat->{"expected-downtime"} || 0;
+
 		#reduce sleep if remainig memory if lower than the everage transfert 
 		$usleep = 300000 if $avglstat && $rem < $avglstat;
 
 		$self->log('info', "migration status: $stat->{status} (transferred ${trans}, " .
-			   "remaining ${rem}), total ${total})");
+			   "remaining ${rem}), total ${total}, expected downtime ${expected_downtime})");
 
 		#$self->log('info', "migration xbzrle cachesize: ${xbzrlecachesize} transferred ${xbzrlebytes} pages ${xbzrlepages} cachemiss ${xbzrlecachemiss} overflow ${xbzrleoverflow}");
 	    }
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 165eaf6..b168c74 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -385,7 +385,6 @@ EODESCR
 	type => 'integer',
 	description => "Set maximum tolerated downtime (in seconds) for migrations.",
 	minimum => 0,
-	default => 1,
     },
     cdrom => {
 	optional => 1,
@@ -2976,21 +2975,6 @@ sub vm_start {
 	    warn $@ if $@;
 	}
 
-	# always set migrate speed (overwrite kvm default of 32m)
-	# we set a very hight default of 8192m which is basically unlimited
-	my $migrate_speed = $defaults->{migrate_speed} || 8192;
-	$migrate_speed = $conf->{migrate_speed} || $migrate_speed;
-	$migrate_speed = $migrate_speed * 1048576;
-	eval {
-	    vm_mon_cmd_nocheck($vmid, "migrate_set_speed", value => $migrate_speed);
-	};
-
-	my $migrate_downtime = $defaults->{migrate_downtime};
-	$migrate_downtime = $conf->{migrate_downtime} if defined($conf->{migrate_downtime});
-	if (defined($migrate_downtime)) {
-	    eval { vm_mon_cmd_nocheck($vmid, "migrate_set_downtime", value => $migrate_downtime); };
-	}
-
 	if($migratedfrom) {
 	    my $capabilities = {};
 	    $capabilities->{capability} =  "xbzrle";
-- 
1.7.10.4




More information about the pve-devel mailing list