]> xenbits.xensource.com Git - osstest.git/commitdiff
duration estimates: Memoise results
authorIan Jackson <ian.jackson@eu.citrix.com>
Wed, 19 Aug 2020 11:55:20 +0000 (12:55 +0100)
committerIan Jackson <ian.jackson@eu.citrix.com>
Wed, 19 Aug 2020 16:01:07 +0000 (17:01 +0100)
The caller may provide a memoisation hash.  If they don't we embed
one in the estimator.

The estimator contains a db statement handle so shouldn't be so
long-lived that this gives significantly wrong answers.

I am aiming this work at ts-hosts-allocate-Executive, but it is
possible that this might speed up sg-report-flight.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Osstest/Executive.pm

index d6b2736b25cf729d91d1a1d176db9aba13c38b17..50c84cc3b74744bf805b541f13016b54e0deca4a 100644 (file)
@@ -1164,8 +1164,8 @@ sub hostalloc_starvation_calculate_X ($$$) {
 
 #---------- duration estimator ----------
 
-sub duration_estimator ($$;$$) {
-    my ($branch, $blessing, $debug, $will_uptoincl_testid) = @_;
+sub duration_estimator ($$;$$$) {
+    my ($branch, $blessing, $debug, $will_uptoincl_testid, $our_memo) = @_;
     # returns a function which you call like this
     #    $durest->($job, $hostidname, $onhost [, $uptoincl_testid])
     # and returns one of
@@ -1269,9 +1269,15 @@ END
     my $recentflights_q= $prepare_combi->($recentflights_qtxt);
     my $duration_anyref_q= $prepare_combi->($duration_anyref_qtxt);
 
+    $our_memo //= { };
+
     return sub {
         my ($job, $hostidname, $onhost, $uptoincl_testid) = @_;
 
+       my $memokey = "$job $hostidname $onhost $uptoincl_testid";
+       my $memo = $our_memo->{$memokey};
+       return @$memo if $memo;
+
        my @x_params;
        push @x_params, $uptoincl_testid if $will_uptoincl_testid;
 
@@ -1319,7 +1325,9 @@ END
             }
         }
 
-        return ($duration_max, $refs->[0]{started}, $refs->[0]{status});
+       $memo = [$duration_max, $refs->[0]{started}, $refs->[0]{status}];
+       $our_memo->{$memokey} = $memo;
+        return @$memo;
     };
 }