[Tools 1/3] testbot: Better deal with $MaxVMsWhenIdle > $MaxActiveVMs.

Francois Gouget fgouget at codeweavers.com
Fri Oct 20 09:15:17 CDT 2017


Make sure we limit the number of running VMs to $MaxActiveVMs even if we
have more idle VMs ready, such as when $MaxVMsWhenIdle > $MaxActiveVMs.
For instance this allows preparing two or three VMs for future jobs, 
while still running the tasks one by one once there is a job to run.
Also prevent the premature powering off of the extra idle VMs that are
going to be used next (like we do for VMs that will be needed for the
current jobs next steps).

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
 testbot/lib/WineTestBot/Jobs.pm | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/testbot/lib/WineTestBot/Jobs.pm b/testbot/lib/WineTestBot/Jobs.pm
index de639c72..3a3e5177 100644
--- a/testbot/lib/WineTestBot/Jobs.pm
+++ b/testbot/lib/WineTestBot/Jobs.pm
@@ -457,8 +457,11 @@ reverting too many VMs at once.
 =item *
 
 Once there are no jobs to run anymore the scheduler can prepare up to
-$MaxVMsWhenIdle VMs (or $MaxActiveVMs if not set) for future jobs. This can be
-set to 0 to minimize the TestBot resource usage when idle.
+$MaxVMsWhenIdle VMs (or $MaxActiveVMs if not set) for future jobs.
+This can be set to 0 to minimize the TestBot resource usage when idle.
+This can also be set to a value greater than $MaxActiveVMs. Then only
+$MaxActiveVMs tasks will be run simultaneously but the extra idle VMs will be
+kept on standby so they are ready when their turn comes.
 
 =cut
 
@@ -546,23 +549,28 @@ sub ScheduleOnHost($$$)
         next if (!$HostVMs->ItemExists($VMKey) || exists $VMsToRevert{$VMKey});
 
         my $VMStatus = $VM->Status;
-        if ($VMStatus eq "idle" &&
-            ($RevertingCount == 0 || $MaxRevertsWhileRunningVMs > 0))
+        if ($VMStatus eq "idle")
         {
+          # Even if we cannot start the task right away this VM is not a
+          # candidate for shutdown since it will be needed next.
           $IdleVMs{$VMKey} = 0;
-          $IdleCount--;
-
-          my $ErrMessage = $Task->Run($Step);
-          return $ErrMessage if (defined $ErrMessage);
 
-          $Job->UpdateStatus();
-          $RunningCount++;
-          $PrepareNextStep = 1;
+          if ($RunningCount < $MaxActiveVMs and
+              ($RevertingCount == 0 || $RevertingCount < $MaxRevertsWhileRunningVMs))
+          {
+            my $ErrMessage = $Task->Run($Step);
+            return $ErrMessage if (defined $ErrMessage);
+
+            $Job->UpdateStatus();
+            $IdleCount--;
+            $RunningCount++;
+            $PrepareNextStep = 1;
+          }
         }
         elsif ($VMStatus eq "sleeping" and $IdleVMs{$VMKey})
         {
           # It's not running jobs yet but soon will be
-          # so it's not a candidate for shutdown.
+          # so it's not a candidate for shutdown or revert.
           $IdleVMs{$VMKey} = 0;
           $IdleCount--;
           $SleepingCount++;
@@ -587,7 +595,7 @@ sub ScheduleOnHost($$$)
           my $VM = $Task->VM;
           my $VMKey = $VM->GetKey();
           push @VMsNext, $VMKey;
-          # Not a candidate for shutdown
+          # If idle already this is not a candidate for shutdown
           $IdleVMs{$VMKey} = 0;
         }
       }
@@ -667,11 +675,11 @@ sub ScheduleOnHost($$$)
     $ActiveCount++ if ($VM->Status eq "off");
   }
 
-  # Prepare some VMs for the current jobs next step
+  # Prepare some VMs for the next step of the current jobs
   foreach my $VMKey (@VMsNext)
   {
     last if ($RevertingCount == $MaxReverts);
-    last if ($ActiveCount == $MaxActiveVMs);
+    last if ($ActiveCount >= $MaxActiveVMs);
 
     my $VM = $HostVMs->GetItem($VMKey);
     next if ($VM->Status ne "off");
-- 
2.14.2




More information about the wine-patches mailing list