[pve-devel] [PATCH 6/7] live migration: reduce sleep when remaining memory is low

Alexandre Derumier aderumier at odiso.com
Thu Aug 16 07:25:26 CEST 2012


Reduce sleep to 0.3s when remaining memory is lower than the average transfert in 1 iteration.

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuMigrate.pm |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 6d717c8..cb015cc 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -9,6 +9,7 @@ use PVE::INotify;
 use PVE::Cluster;
 use PVE::Storage;
 use PVE::QemuServer;
+use Time::HiRes qw( usleep );
 
 use base qw(PVE::AbstractMigrate);
 
@@ -330,8 +331,13 @@ sub phase2 {
     my $merr = $@;
 
     my $lstat = 0;
+    my $usleep = 2000000;
+    my $i = 0;
     while (1) {
-	sleep (2);
+	$i++;
+	my $avglstat = $lstat/$i if $lstat;
+
+	usleep ($usleep);
 	my $stat = PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "query-migrate");
 	if ($stat->{status} =~ m/^(active|completed|failed|cancelled)$/im) {
 	    $merr = undef;
@@ -357,13 +363,15 @@ sub phase2 {
 		my $trans = $stat->{ram}->{transferred} || 0;
 		my $rem = $stat->{ram}->{remaining} || 0;
 		my $total = $stat->{ram}->{total} || 0;
+		#reduce sleep if remainig memory if lower than the everage transfert 
+		$usleep = 300000 if $rem < $avglstat;
 
 		$self->log('info', "migration status: $stat->{status} (transferred ${trans}, " .
 			   "remaining ${rem}), total ${total})");
 	    }
 
 	    $lstat = $stat->{ram}->{transferred};
-
+	    
 	} else {
 	    die $merr if $merr;
 	    die "unable to parse migration status '$stat->{status}' - aborting\n";
-- 
1.7.2.5




More information about the pve-devel mailing list