Skip to contentSkip to conversation

Planner: Performance improvement

PATCH In review Ian Jackson 2 participants 32 messages Sep 7, 2015 – Sep 8, 2015

lore
Share & tools
lore
#0 lore raw

v2 cover Planner: Performance improvement

This series addresses a performance problem which we seem to be experiencing with the existing osstest resource planner in Xen Project test colo. The current setup can leave hosts idle for too long before getting around to allocating them to test jobs.

There are also some reporting/debugging improvements.

The full explanation of the new algorithm is in the commit message for
14/29 Planner: ms-queuedaemon: Restart planning when resources become free

Most of this series touches code in the central queue daemon, or in command line tools, and is not subject to the osstest self-push-gate.

I have extensively tested this series in the Cambridge instance, where this version of ms-queuedaemon is currently running and seems to be happy. The queuedaemon changes and the client (per-flight) changes are fully compatible in both directions (except for Ian C's out-of-mainline reporting tool which calls `get-plan' and is already rather broken).

#1 lore raw

PATCH v2 1/29 Tcl: Use lshift instead of open-coding with lrange

In ms-queuedaemon, and JobDB-Executive, once each. No functional change.

---
 ms-queuedaemon          |    3 +--
 tcl/JobDB-Executive.tcl |    3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
ms-queuedaemon +1 -2
index e15bc79..d6d59ee 100755
@@ -210,8 +210,7 @@ proc queuerun-perhaps-step {} {
         return
     }
 
-    set thinking [lindex $queue_running 0]
-    set queue_running [lrange $queue_running 1 end]
+    set thinking [lshift queue_running]
     log-event "queuerun-perhaps-step selected"
 
     set thinking_after [after [expr {$c(QueueThoughtsTimeout) * 1000}] \
tcl/JobDB-Executive.tcl +1 -2
index 7228712..d61d2a2 100644
@@ -74,8 +74,7 @@ proc set-flight {} {
         set argv [lrange $argv 2 end]
     }
 
-    set flight [lindex $argv 0]
-    set argv [lrange $argv 1 end]
+    set flight [lshift argv]
     set env(OSSTEST_FLIGHT) $flight
 }
 
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH v2 2/29 Planner: docs: Minor fixes

In reply to Ian Jackson

* Document the ms-queuedaemon banner
* Document the argument to the allocation $resourcecall callback fn.

---
 Osstest/Executive.pm |    2 +-
 README.planner       |    3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)
Osstest/Executive.pm +1 -1
index bf968c8..ab015d2 100644
@@ -604,7 +604,7 @@ sub plan_search ($$$$) {
 }
 
 sub alloc_resources {
-    my ($resourcecall) = pop @_;
+    my ($resourcecall) = pop @_; # $resourcecall->($plan);
     my (%xparams) = @_;
     # $resourcecall should die (abort) or return ($ok, $bookinglist)
     #
README.planner +3 -0
index 73e97ea..4cf682d 100644
@@ -181,6 +181,9 @@ DETAILED PROTOCOL NOTES
 
 ms-queuedaemon commands
 
+        < OK ms-queuedaemon [INFO...]
+                Banner on connection.  INFO should be ignored.
+
 	> wait
 		I want to join the plan
 
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH v2 3/29 Planner: docs: Document set-info command

In reply to Ian Jackson
---
 README.planner |   10 ++++++++++
 1 file changed, 10 insertions(+)
README.planner +10 -0
index 4cf682d..ef2acba 100644
@@ -184,6 +184,16 @@ ms-queuedaemon commands
         < OK ms-queuedaemon [INFO...]
                 Banner on connection.  INFO should be ignored.
 
+        > set-info KEY VALUE
+                There are various informational keys which are used by
+                the planner, provided by clients.  Keys include:
+
+        > set-info preinfo ...                   } used for reporting
+        > set-info job ...                       }
+        > set-info priority ...                      } used for
+        > set-info sub-priority ...                  } queue adjustment
+        > set-info wait-start-adjust ...             }
+
 	> wait
 		I want to join the plan
 
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH v2 4/29 Planner: Fix indefinite holdoff

In reply to Ian Jackson

runneeded-ensure-will would always reset the runneeded_holdoff_after timer. So no new queue run would start until no runneeded-ensure-will has occurred for (currently) 30s.

Instead, only start the timer if it's not already running.

---
 ms-queuedaemon |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
ms-queuedaemon +6 -4
index d6d59ee..1aa526c 100755
@@ -86,10 +86,12 @@ proc runneeded-ensure-will {need} {
     log-event "runneeded-ensure-will $need (was $need_queue_run)"
 
     if {$need > $need_queue_run} { set need_queue_run $need }
-    catch { after cancel $runneeded_holdoff_after }
-    set runneeded_holdoff_after \
-        [after [expr {$c(QueueDaemonHoldoff) * 1000}] \
-             runneeded-perhaps-start]
+
+    if {![info exists runneeded_holdoff_after]} {
+	set runneeded_holdoff_after \
+	    [after [expr {$c(QueueDaemonHoldoff) * 1000}] \
+		 runneeded-perhaps-start]
+    }
 }
 
 proc runneeded-perhaps-start {} {
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH v2 5/29 Planner: client side: $mayalloc parameter to $resourcecall->()

In reply to Ian Jackson

Add a new parameter to $resourcecall which allows the alloc_resources loop in Osstest::Executive to specify to its clients that on this occasion they should not make any actual allocations.

The callers of alloc_resources are all adjusted to honour this new parameter:
* ts-hosts-allocate-Executive avoids allocating unless $mayalloc
* mg-allocate avoids allocating unless $mayalloc
* mg-blockage never allocates anyway.

Currently we always pass 1, so no functional change.

---
 Osstest/Executive.pm        |    4 ++--
 mg-allocate                 |    4 ++--
 mg-blockage                 |    2 +-
 ts-hosts-allocate-Executive |    4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)
Osstest/Executive.pm +2 -2
index ab015d2..f9be0a0 100644
@@ -604,7 +604,7 @@ sub plan_search ($$$$) {
 }
 
 sub alloc_resources {
-    my ($resourcecall) = pop @_; # $resourcecall->($plan);
+    my ($resourcecall) = pop @_; # $resourcecall->($plan, $mayalloc);
     my (%xparams) = @_;
     # $resourcecall should die (abort) or return ($ok, $bookinglist)
     #
@@ -720,7 +720,7 @@ sub alloc_resources {
 		$plan= from_json($jplan);
 	    }, sub {
 		if (!eval {
-		    ($ok, $bookinglist) = $resourcecall->($plan);
+		    ($ok, $bookinglist) = $resourcecall->($plan, 1);
 		    1;
 		}) {
 		    warn "resourcecall $@";
mg-allocate +2 -2
index fc1b394..6dc7ddd 100755
@@ -270,7 +270,7 @@ sub showposs ($) {
 sub plan () {
     my @got;
     alloc_resources(sub {
-        my ($plan) = @_;
+        my ($plan, $mayalloc) = @_;
 
 	@got = ();
         my @possmatrix = ([]);
@@ -310,7 +310,7 @@ sub plan () {
 	die unless $planned;
 
         my $allok=0;
-        if (!$planned->{Start}) {
+        if ($mayalloc && !$planned->{Start}) {
             $allok=1;
 
             alloc_prep();
mg-blockage +1 -1
index a21f15b..1f66d8e 100755
@@ -40,7 +40,7 @@ sub max { (reverse sort @_)[0]; }
 
 sub plan () {
     alloc_resources(sub {
-	my ($plan) = @_;
+	my ($plan, $mayalloc) = @_;
 
 	my $now = time;
 	if ($now > $end) { return (1, { Bookings => [ ] }); }
ts-hosts-allocate-Executive +2 -2
index 6583191..4c7c614 100755
@@ -606,7 +606,7 @@ sub alloc_hosts () {
 }
 
 sub attempt_allocation {
-    ($plan) = @_;
+    ($plan, $mayalloc) = @_;
     undef $best;
 
     logm("allocating hosts: ".join(' ', map { $_->{Ident} } @hids));
@@ -632,7 +632,7 @@ sub attempt_allocation {
 
     my $retval=0;
 
-    if (!$best->{Start}) {
+    if ($mayalloc && !$best->{Start}) {
 	$retval= 1;
 	foreach my $hid (@hids) {
 	    my $got= actual_allocation($hid);
Signature · 1 line
1.7.10.4
#6 lore raw

PATCH v2 6/29 Planner: client side: New `!OK think noalloc' protocol

In reply to Ian Jackson

Introduce a way for the queue daemon to tell its client that it must not allocate anything in this planning iteration.

In the client:
* Advertise the new feature via set-info.
* Accept the noalloc' part of !OK think noalloc';
* Print that in our log message;
* Honour it by passing it to $resourcecall.

And document the new protocol. However, there is no server-side yet, so this does not yet introduce any overall change to the system.

---
 Osstest/Executive.pm |    9 ++++++---
 README.planner       |    6 +++++-
 2 files changed, 11 insertions(+), 4 deletions(-)
Osstest/Executive.pm +6 -3
index f9be0a0..4f51d70 100644
@@ -674,6 +674,7 @@ sub alloc_resources {
                 $set_info->('priority', $priority);
                 $set_info->('sub-priority',$ENV{OSSTEST_RESOURCE_SUBPRIORITY});
                 $set_info->('preinfo',     $ENV{OSSTEST_RESOURCE_PREINFO});
+		$set_info->('feature-noalloc', 1);
 
                 if (defined $waitstart) {
                     $set_info->('wait-start',$waitstart);
@@ -699,7 +700,9 @@ sub alloc_resources {
 
             logm("resource allocation: awaiting our slot...");
 
-            $_= <$qserv>;  defined && m/^\!OK think\s$/ or die "$_ ?";
+            $_= <$qserv>;
+	    defined && m/^\!OK think( noalloc)?\s$/ or die "$_ ?";
+	    my $noalloc = $1 // '';
 
             opendb_tests();
 
@@ -715,12 +718,12 @@ sub alloc_resources {
 		read($qserv, $jplan, $jplanlen) == $jplanlen or die $!;
 		my $jplanprint= $jplan;
 		chomp $jplanprint;
-		logm("resource allocation: obtained base plan.");
+		logm("resource allocation: obtained base plan$noalloc.");
 		$debugm->("base plan = ", $jplanprint);
 		$plan= from_json($jplan);
 	    }, sub {
 		if (!eval {
-		    ($ok, $bookinglist) = $resourcecall->($plan, 1);
+		    ($ok, $bookinglist) = $resourcecall->($plan, !$noalloc);
 		    1;
 		}) {
 		    warn "resourcecall $@";
README.planner +5 -1
index ef2acba..52f757b 100644
@@ -194,11 +194,15 @@ ms-queuedaemon commands
         > set-info sub-priority ...                  } queue adjustment
         > set-info wait-start-adjust ...             }
 
+        > set-info feature-noalloc 1
+	        The client understands `!OK think noalloc'.
+
 	> wait
 		I want to join the plan
 
-	< !OK think
+	< !OK think [noalloc]
 		Now is the time to add yourself to the plan
+                `noalloc' means client must not not actually allocate.
 
 		> get-plan
 		< OK get-plan BYTES
Signature · 1 line
1.7.10.4
#7 lore raw

PATCH v2 7/29 Planner: client side: Do not force OSSTEST_RESOURCE_PRIORITY

In reply to Ian Jackson

This makes it possible to run mg-allocate with a different priority simply by setting OSSTEST_RESOURCE_PRIORITY in its environment.

---
v2: New patch

---
 mg-allocate |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mg-allocate +1 -1
index 6dc7ddd..14c9088 100755
@@ -365,7 +365,7 @@ while (@ARGV && $ARGV[0] =~ m/^[-0-9]/) {
                              $2 eq 'm' ?    60 :
                                              1);
         } elsif (s/^\-U/-/) {
-            $ENV{OSSTEST_RESOURCE_PRIORITY}= -1000000;
+            $ENV{OSSTEST_RESOURCE_PRIORITY} //= -1000000;
         } else {
             die "bad option \`$_'";
         }
Signature · 1 line
1.7.10.4
Acked-by on v2 7/29
#8 lore raw

Re: [OSSTEST PATCH 07/29] Planner: client side: Do not force OSSTEST_RESOURCE_PRIORITY

Quoted 4 lines · Ian Jackson

This makes it possible to run mg-allocate with a different priority simply by setting OSSTEST_RESOURCE_PRIORITY in its environment.

Quoted 19 lines

---
v2: New patch

---
 mg-allocate |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mg-allocate +1 -1
index 6dc7ddd..14c9088 100755
@@ -365,7 +365,7 @@ while (@ARGV && $ARGV[0] =~ m/^[-0-9]/) {
                              $2 eq 'm' ?    60 :
                                              1);
         } elsif (s/^\-U/-/) {
-            $ENV{OSSTEST_RESOURCE_PRIORITY}= -1000000;
+            $ENV{OSSTEST_RESOURCE_PRIORITY} //= -1000000;
         } else {
             die "bad option \`$_'";
         }
#9 lore raw

PATCH v2 8/29 Planner: ms-planner support -w option

In reply to Ian Jackson

We are going to introduce multiple concurrent streams of planning processing, called `walkers' in ms-queuedaemon. The work-in-progress plan is stored, server-side, during planning, in data-plan.pl. But we need to have more than one of these.

Update ms-planner and ms-planner-debug to honour a -w option, to specify a replacement for the word plan' in data-plan.pl'.

No overall functional change, since nothing uses these options yet.

---
 ms-planner       |    6 +++++-
 ms-planner-debug |   13 ++++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)
ms-planner +5 -1
index f38f05b..053f330 100755
@@ -33,12 +33,16 @@ use Osstest::Executive;
 
 open DEBUG, ">/dev/null" or die $!;
 
+our $walker = 'plan';
+
 while (@ARGV and $ARGV[0] =~ m/^-/) {
     $_= shift @ARGV;
     last if m/^--$/;
     while (m/^-./) {
         if (s/^-D/-/) {
             open DEBUG, ">&STDERR" or die $!;
+        } elsif (s/^-w(.+)/-/) {
+	    $walker = $1;
         } else {
             die "$_ ?";
         }
@@ -49,7 +53,7 @@ csreadconfig();
 
 our ($plan);
 
-my $fn= "data-plan.pl";
+my $fn= "data-$walker.pl";
 
 sub allocations ($$) {
     my ($init, $each) = @_;
ms-planner-debug +10 -3
index e277ca6..eac5675 100755
@@ -25,7 +25,14 @@ use Osstest;
 
 csreadconfig();
 
-my $f= sprintf "data-plan-debug-%s.txt", time;
+my $walker = 'plan';
+
+if (@ARGV && $ARGV[0] =~ m/^-w(.+)$/) {
+    $walker = $1;
+    shift @ARGV;
+}
+
+my $f= sprintf "data-$walker-debug-%s.txt", time;
 
 printf "%s\n", $f;
 
@@ -42,9 +49,9 @@ foreach my $arg (@ARGV) {
     }
 }
 
-print "==========data-plan.pl==========\n";
+print "==========data-$walker.pl==========\n";
 
-system 'cat data-plan.pl 2>&1';
+system 'cat data-$walker.pl 2>&1';
 
 print "==========resources==========\n";
 
Signature · 1 line
1.7.10.4
#10 lore raw

PATCH v2 9/29 Planner: ms-queuedaemon: Prep for multiple walkers

In reply to Ian Jackson

We are going to introduce multiple concurrent streams of planning processing, called `walkers'.

Prepare the ground for this with some formulaic changes which will otherwise greatly clutter substantive patches.

(A client will still only think for one walker at once, because that's what the client protocol expects - and anything else would be far too confusing.)

General:
* Introduce the concept of a `walker' to ms-queuedaemon.
* Provide a list of the walkers which might exist, `walkers'
* Provide some helper procedures for iterating over these, and easily accessing their state.

Queue handling:
* Add a new w' argument to many procs: specifically, most of the procs in the section machinery for running the queue'.
* Log the walker ($w) at the start of all relevant log messages.
* Pass the -w option to ms-planner and ms-planner-debug.
* Add safety catches which will crash the ms-queuedaemon if it finds it is asking the same client to think for more than one walker.
* we-are-thinking and check-we-are-thinking tell the caller what walker the client is thinking for.
* In the resource-plan.html filename, replace `plan' with the walker filename.

Elsewhere:
* Teach dequeue-chan to deal with all the walkers, including maybe the (one) walker for which the client is thinking.
* Teach log-state to report on all the walkers.
* In the runneeded logic, hardcode `plan' as the walker to use.

There is still actually only one walker.

No overall functional change, except to some log messages.

---
v2: Fix walker-globals to import the $w/$v from #0, ie the global scope
Correct invocation of upvar in walker-globals
Use walker-globals everywhere, not obsolete name walker-vars Do not pass w to do-book-resources (which does not want it
because it uses uses chan-we-are-thinking)

---
 ms-queuedaemon |  189 +++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 120 insertions(+), 69 deletions(-)
ms-queuedaemon +120 -69
index 1aa526c..6e1ba0e 100755
@@ -21,6 +21,23 @@
 
 source ./tcl/daemonlib.tcl
 
+set walkers {plan}
+
+proc walker-globals {w} {
+    # introduces queue_running, thinking[_after] for the specific walker
+    foreach v {queue_running thinking thinking_after} {
+	uplevel 1 [list upvar #0 $w/$v $v]
+    }
+}
+
+proc foreach-walker {walkervar body} {
+    global walkers
+    upvar 1 $walkervar w
+    foreach w $walkers {
+	uplevel 1 walker-globals $w
+	uplevel 1 $body
+    }
+}
 
 proc chan-destroy-stuff {chan} {
     dequeue-chan $chan destroy
@@ -31,13 +48,20 @@ proc chan-destroy-stuff {chan} {
 proc dequeue-chan {chan why} {
     log-event "dequeue-chan $chan $why"
 
-    global queue queue_running thinking
+    global queue
     lremove queue $chan
 
-    if {[info exists queue_running]} { lremove queue_running $chan }
-    if {[info exists thinking] &&
-        ![string compare $thinking $chan]} {
-        queuerun-step-done $why
+    foreach-walker w {
+	if {[info exists queue_running]} { lremove queue_running $chan }
+    }
+
+    # Reentrancy: this next loop can only trigger once, because
+    # the queuerun-step-done won't ever start chan thinking again
+    foreach-walker w {
+	if {[info exists thinking] &&
+	    ![string compare $thinking $chan]} {
+	    queuerun-step-done $w $why
+	}
     }
 }
 
@@ -55,31 +79,35 @@ proc log-event {m} {
 }
 
 proc log-state {m} {
-    global need_queue_run queue queue_running thinking
+    global need_queue_run queue
 
     set lhs [format "N=%d Q=%d (%-11.11s) " \
                  $need_queue_run [llength $queue] $queue]
 
-    if {[info exists queue_running]} {
-        append lhs [format "R=%d " [llength $queue_running]]
-        if {[info exists thinking]} {
-            append lhs [format "T=%s " $thinking]
-        } else {
-            append lhs [format "        "]
-        }
-        append lhs [format "(%-11.11s) " $queue_running]
-    } else {
-        append lhs "                          "
+    foreach-walker w {
+	if {[info exists queue_running]} {
+	    append lhs [format "R=%d " [llength $queue_running]]
+	    if {[info exists thinking]} {
+		append lhs [format "T=%s " $thinking]
+	    } else {
+		append lhs [format "        "]
+	    }
+	    append lhs [format "(%-11.11s) " $queue_running]
+	} else {
+	    append lhs "                          "
+	}
     }
+
     log "$lhs | $m"
 }
 
 #---------- machinery for making sure we run the queue ----------
 #
 # variables:
-#   queue            chans that are waiting for resources
-#   queue_running    unset if not running, list of chans if running
-#   need_queue_run   0: not needed; 1: needed if more resources; 2: force
+#  $w/queue            chans that are waiting for resources
+#  $w/queue_running    unset if not running, list of chans if running
+#  need_queue_run      0: not needed; 1: needed if more resources; 2: force
+# the $w/ variables are generally upvar'd with walker-globals
 
 proc runneeded-ensure-will {need} {
     global runneeded_holdoff_after c need_queue_run
@@ -96,7 +124,8 @@ proc runneeded-ensure-will {need} {
 
 proc runneeded-perhaps-start {} {
     log-event runneeded-perhaps-start
-    global queue queue_running thinking need_queue_run inhibit
+    walker-globals plan
+    global queue need_queue_run inhibit
     global runneeded_holdoff_after
     unset runneeded_holdoff_after
 
@@ -108,8 +137,8 @@ proc runneeded-perhaps-start {} {
     set need_queue_run 0
 
     if {![llength $queue]} {
-        plan-reset
-        report-plan
+        plan-reset plan
+        report-plan plan
         return
     }
 
@@ -140,7 +169,7 @@ proc runneeded-perhaps-start {} {
     log "runneeded-perhaps-start starting cleaned=$cleaned"
 
     runneeded-2-requeue
-    queuerun-start
+    queuerun-start plan
 }
 
 proc runneeded-ensure-polling {} {
@@ -181,26 +210,29 @@ proc runneeded-2-requeue {} {
 #---------- machinery for running the queue ----------
 #
 # variables:
-#    queue             chans waiting, read when we start
-#    queue_running     chans not yet asked
-#    thinking          chan currently asking
-#    thinking_after    timeout
+#  queue                chans waiting, read when we start
+#  $w/queue_running     chans not yet asked
+#  $w/thinking          chan currently asking
+#  $w/thinking_after    timeout
+# all the $w/ are generally upvar'd by walker-globals
 
-proc plan-reset {} {
-    exec ./ms-planner reset < /dev/null
+proc plan-reset {w} {
+    exec ./ms-planner -w$w reset < /dev/null
 }
 
-proc queuerun-start {} {
-    log-event queuerun-start
-    global queue_running queue
-    plan-reset
+proc queuerun-start {w} {
+    global queue
+    walker-globals $w
+    log-event "$w queuerun-start"
+    plan-reset $w
     set queue_running $queue
-    after idle queuerun-perhaps-step
+    after idle queuerun-perhaps-step plan
 }
 
-proc queuerun-perhaps-step {} {
-    log-event queuerun-perhaps-step
-    global thinking queue_running thinking_after c
+proc queuerun-perhaps-step {w} {
+    log-event "$w queuerun-perhaps-step"
+    walker-globals $w
+    global c
 
     if {[info exists thinking]} return
     if {![info exists queue_running]} return
@@ -208,107 +240,126 @@ proc queuerun-perhaps-step {} {
     if {![llength $queue_running]} {
         unset queue_running
         runneeded-ensure-will 0
-        report-plan
+        report-plan $w
         return
     }
 
-    set thinking [lshift queue_running]
-    log-event "queuerun-perhaps-step selected"
+    set next [lindex $queue_running 0]
+    set already [we-are-thinking $next]
+    if {[llength $already]} {
+	error "next $next thinking $already but also want $w"
+    }
+
+    set thinking $next
+    lshift queue_running
+    log-event "$w queuerun-perhaps-step selected"
 
     set thinking_after [after [expr {$c(QueueThoughtsTimeout) * 1000}] \
-                            queue-thoughts-timedout]
+                            queue-thoughts-timedout $w]
     for-chan $thinking {
         puts-chan $thinking "!OK think"
     }
 }
 
-proc report-plan {} {
+proc report-plan {w} {
     global c
     if {[catch {
-        exec ./ms-planner show-html > "$c(WebspaceFile)/resource-plan.html"
+	set outputfile "$c(WebspaceFile)/resource-$w.html"
+	exec ./ms-planner -w$w show-html > $outputfile
     } emsg]} {
-        log "INTERNAL ERROR showing plan html: $emsg"
+        log "INTERNAL ERROR showing $w html: $emsg"
     } else {
-        log "report-plan OK"
+        log "$w report-plan OK"
     }
 }
 
 proc we-are-thinking {chan} {
-    global thinking
-    return [expr {[info exists thinking] && ![string compare $thinking $chan]}]
+    set ws {}
+    foreach-walker w {
+	if {[info exists thinking] && ![string compare $thinking $chan]} {
+	    lappend ws $w
+	}
+    }
+    if {[llength $ws] > 1} {
+	error "arrgh chan $chan thinking $ws !"
+    }
+    return [lindex $ws 0]
 }
 
 proc check-we-are-thinking {chan} {
-    if {![we-are-thinking $chan]} {
+    set w [we-are-thinking $chan]
+    if {![string length $w]} {
         puts-chan $chan "ERROR you are not thinking"
         return -code return
     }
+    return $w
 }
 
-proc queuerun-step-done {why} {
-    log-event "queuerun-step-done $why"
-    global queue_running thinking thinking_after
-    puts-chan-desc $thinking "queuerun-step-done $thinking $why"
+proc queuerun-step-done {w why} {
+    log-event "$w queuerun-step-done $why"
+    walker-globals $w
+    puts-chan-desc $thinking "$w queuerun-step-done $thinking $why"
     if {[info exists thinking_after]} {
         after cancel $thinking_after
         unset thinking_after
     }
     unset thinking
-    after idle queuerun-perhaps-step
+    after idle queuerun-perhaps-step $w
 }
 
-proc queue-thoughts-timedout {} {
-    log-event queue-thoughts-timedout
-    global thinking thinking_after
+proc queue-thoughts-timedout {w} {
+    log-event "$w queue-thoughts-timedout"
+    walker-globals $w
     set chan $thinking
     unset thinking_after
-    queuerun-step-done timeout
+    queuerun-step-done $w timeout
     for-chan $chan {
         puts-chan $chan "!ERROR timed out (too pensive)"
     }
 }
 
 proc cmd/thought-wait {chan desc} {
-    check-we-are-thinking $chan
-    queuerun-step-done thought-wait
+    set w [check-we-are-thinking $chan]
+    queuerun-step-done $w thought-wait
     puts-chan $chan "OK thought"
 }
 
 proc cmd/thought-done {chan desc} {
-    check-we-are-thinking $chan
-    queuerun-step-done thought-done
+    set w [check-we-are-thinking $chan]
+    queuerun-step-done $w thought-done
     dequeue-chan $chan thought-wait
     puts-chan $chan "OK thought"
 }
 
 proc cmd/get-plan {chan desc} {
     global plan
-    set plan [exec -keepnewline ./ms-planner get-plan < /dev/null]
+    set w [check-we-are-thinking $chan]
+    set plan [exec -keepnewline ./ms-planner -w$w get-plan < /dev/null]
     puts-chan-data $chan "OK get-plan" $plan
 }
 
 proc cmd/book-resources {chan desc bytes} {
-    check-we-are-thinking $chan
     read-chan-data $chan $bytes do-book-resources
 }
 proc do-book-resources {chan desc data} {
     global plan errorInfo
-    check-we-are-thinking $chan
+    set w [check-we-are-thinking $chan]
     set info [chan-get-info $chan {"$info(preinfo) "} ""]
     append info [chan-get-info $chan {"job $info(job)"} $desc]
     if {[catch {
-	exec ./ms-planner book-resources $info << $data
+	exec ./ms-planner -w$w book-resources $info << $data
     } emsg]} {
-	set f [exec ./ms-planner-debug $info $data $plan]
+	set f [exec ./ms-planner-debug -w$w $info $data $plan]
 	error "$f $emsg" $errorInfo
     }
     puts-chan $chan "OK book-resources"
 }
 
 proc cmd/unwait {chan desc} {
-    if {[we-are-thinking $chan]} {
-        queuerun-step-done unwait
-        set res cancel
+    set w [we-are-thinking $chan]
+    if {[string length $w]} {
+        queuerun-step-done $w unwait
+        set res "$w cancel"
     } else {
         set res noop
     }
Signature · 1 line
1.7.10.4
#11 lore raw

PATCH v2 10/29 Planner: ms-queuedaemon: Synchronise thinking multiple walkers

In reply to Ian Jackson

If multiple walkers want to ask the same chan, we want to serialise them. This is actually straightforward: Firstly, we arrrange that each walker finishing a thought will prompt _all_ walkers to reconsider whether they need to continue. Then we can simply do nothing if we want to a chan to think that another walker is already waiting for; since that other walker will prompt us later.

Still no actual functional change because there is still only one walker.

---
 ms-queuedaemon |   14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
ms-queuedaemon +11 -3
index 6e1ba0e..d51fd52 100755
@@ -216,6 +216,12 @@ proc runneeded-2-requeue {} {
 #  $w/thinking_after    timeout
 # all the $w/ are generally upvar'd by walker-globals
 
+proc walkers-perhaps-queue-steps {} {
+    foreach-walker w {
+	after idle queuerun-perhaps-step $w
+    }
+}
+
 proc plan-reset {w} {
     exec ./ms-planner -w$w reset < /dev/null
 }
@@ -226,7 +232,7 @@ proc queuerun-start {w} {
     log-event "$w queuerun-start"
     plan-reset $w
     set queue_running $queue
-    after idle queuerun-perhaps-step plan
+    walkers-perhaps-queue-steps
 }
 
 proc queuerun-perhaps-step {w} {
@@ -247,7 +253,9 @@ proc queuerun-perhaps-step {w} {
     set next [lindex $queue_running 0]
     set already [we-are-thinking $next]
     if {[llength $already]} {
-	error "next $next thinking $already but also want $w"
+	# $already will wake us via walkers-perhaps-queue-steps
+	log-event "$w queuerun-perhaps-step already $already"
+	return
     }
 
     set thinking $next
@@ -304,7 +312,7 @@ proc queuerun-step-done {w why} {
         unset thinking_after
     }
     unset thinking
-    after idle queuerun-perhaps-step $w
+    walkers-perhaps-queue-steps
 }
 
 proc queue-thoughts-timedout {w} {
Signature · 1 line
1.7.10.4
#12 lore raw

PATCH v2 11/29 Planner: ms-queuedaemon: Break out queuerun-finished/<walker>

In reply to Ian Jackson

This formalises the queue-completed interface, allowing parts outside the queuerun machinery to cleanly be notified when a queue is completed, and relieving the queuerun-perhaps-step of the need to know what to do for the end of any particular walker's queue.

Currently there is still only one walker, `plan'.

---
 ms-queuedaemon |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
ms-queuedaemon +6 -2
index d51fd52..3026a64 100755
@@ -172,6 +172,11 @@ proc runneeded-perhaps-start {} {
     queuerun-start plan
 }
 
+proc queuerun-finished/plan {} {
+    runneeded-ensure-will 0
+    report-plan plan
+}
+
 proc runneeded-ensure-polling {} {
     log-event runneeded-ensure-polling
     global polling_after queue c
@@ -245,8 +250,7 @@ proc queuerun-perhaps-step {w} {
 
     if {![llength $queue_running]} {
         unset queue_running
-        runneeded-ensure-will 0
-        report-plan $w
+	queuerun-finished/$w
         return
     }
 
Signature · 1 line
1.7.10.4
#13 lore raw

PATCH v2 12/29 Planner: ms-queuedaemon: Break out notify-to-think

In reply to Ian Jackson

This is going to want to do something more complicated shortly.

---
v2: Fix a whitespace error

---
 ms-queuedaemon |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
ms-queuedaemon +8 -3
index 3026a64..1fe555d 100755
@@ -268,9 +268,8 @@ proc queuerun-perhaps-step {w} {
 
     set thinking_after [after [expr {$c(QueueThoughtsTimeout) * 1000}] \
                             queue-thoughts-timedout $w]
-    for-chan $thinking {
-        puts-chan $thinking "!OK think"
-    }
+
+    notify-to-think $w $thinking
 }
 
 proc report-plan {w} {
@@ -379,6 +378,12 @@ proc cmd/unwait {chan desc} {
     puts-chan $chan "OK unwait $res"
 }
 
+proc notify-to-think {w thinking} {
+    for-chan $thinking {
+	puts-chan $thinking "!OK think"
+    }
+}
+
 #---------- general stuff ----------
 
 proc banner {chan} {
Signature · 1 line
1.7.10.4
#14 lore raw

PATCH v2 13/29 Planner: ms-queuedaemon: Make report-plan take output walker name

In reply to Ian Jackson

We are going to want to process each walker's data into reports which are not necessarily named after the same walker.

No functional change as yet.

---
 ms-queuedaemon |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
ms-queuedaemon +4 -4
index 1fe555d..811f0ee 100755
@@ -138,7 +138,7 @@ proc runneeded-perhaps-start {} {
 
     if {![llength $queue]} {
         plan-reset plan
-        report-plan plan
+        report-plan plan plan
         return
     }
 
@@ -174,7 +174,7 @@ proc runneeded-perhaps-start {} {
 
 proc queuerun-finished/plan {} {
     runneeded-ensure-will 0
-    report-plan plan
+    report-plan plan plan
 }
 
 proc runneeded-ensure-polling {} {
@@ -272,10 +272,10 @@ proc queuerun-perhaps-step {w} {
     notify-to-think $w $thinking
 }
 
-proc report-plan {w} {
+proc report-plan {w wo} {
     global c
     if {[catch {
-	set outputfile "$c(WebspaceFile)/resource-$w.html"
+	set outputfile "$c(WebspaceFile)/resource-$wo.html"
 	exec ./ms-planner -w$w show-html > $outputfile
     } emsg]} {
         log "INTERNAL ERROR showing $w html: $emsg"
Signature · 1 line
1.7.10.4
#15 lore raw

PATCH v2 14/29 Planner: ms-queuedaemon: Restart planning when resources become free

In reply to Ian Jackson

This solves a performance problem with the existing planner.

The problem is that with a large installation, and a big queue, a full plan can take a long time to prepare. (In our current installation, perhaps as long as half an hour.) Any resource which becomes free during one plan run cannot be allocated to a new job until the next plan run starts. This means resources (test machines) are often sitting around idle.

Fix this by restarting the planning process as soon as any new resource becomes free. This means that jobs at the front of the queue get a chance to allocate it right away, so it will probably be allocated soon.

If it is only interesting to jobs later in the queue, then there may be a delay in reallocating it, but presumably the resource is not much in demand and those later jobs will allocate it when they get a bit closer to the head.

But, there is a problem with this: it means that the plan is generally never completed. So we have no overview any more of when which flights will finish and what the overall queue is like. We solve this problem by running a second instance of the planner algorithm, all the way to completion, in a dummy' mode where no actual resource allocation takes place. This second projection' instance comes into being whenever the main plan' instance is restarted, and it inherits the planning state from the main plan' instance.

Global livelock (where we keep restarting the plan but never manage to allocate anything) is not possible because each restart involves a new resource becoming free. If nothing gets allocated because we can't get that far before being restarted, then eventually there will be nothing left allocated to become newly free.

Starvation, of a form, is possible: a late-in-queue job which wants a resource available right now might have difficulty allocating it because the planner is spending its effort rescheduling early-in-queue jobs which want resources which are in greater demand - so that the late-in-queue job never gets called. Arguably this is an appropriate allocation of planning time.

With this arrangement we can generate two reports: a plan' report containing the short term plan which was used for actual resource allocation, and which is frequently restarted and therefore not necessarily complete; and a projection' report which contains a complete plan for all work the system is currently aware of, but which is less-frequently updated.

Because planner clients do not contain the planning algorithm state, the only client change needed is the ability to run in a dummy' mode without actual allocation; this is the noalloc' feature earlier in this series.

The main work is in ms-queuedaemon. We have prepared the ground for multiple instances of the planning algorithm; from the point of view of ms-queuedaemon, an instance of the planning algorithm is mainly a walk over the job queue. So we call them `walkers'.

Therefore, what we do here is introduce a new `projection' walker, as follows:

Add `projection' to the global list of possible walkers.

Invent a new section of code, the `restarter', which is responsible for managing the relationship between the two walkers. (It uses direct knowledge of the queue state data structures, etc., to avoid having to invent a complete formal interface to a walker.)

If we ever finish the plan walker's queue, we update both the projection report output and the plan report output, from the same plan. Finishing the projection walker's queue means we have a complete projection, but we don't touch the plan.

In principle it might happen that the plan walker might overtake the projection walker, and then complete, write out a complete and up to date plan as the projection, and that the projection walker would then complete and overwrite the projection with less-up-to-date information. We don't explicitly exclude this. Of course such a result will be rectified soon enough by another planning run.

The restarter can ask the database for the list of currently-available resources, and can therefore detect when new become newly-free.

The rest of the code remains largely ignorant of the operation of the restarter. There are a few hooks:

runneeded-perhaps-start notifies the restarter when we start the plan; this is used by the restarter to record the set of free resources at the start of a planning run, so that it can see later whether any /new/ resources have become free.

restarter-maybe-provoke-restart is called when we get notification from the the owner daemon that resources may have become idle. We look for newly-idle resources, and if there are any, and we are running the plan walker, we directly edit the plan walker's queue to put RESTART at the front.

queuerun-perhaps-step spots the special entry RESTART in its queue and calls into back the restarter when it finds it. This deferred approach is necessary because we can't do the restart operation while a client is thinking (because we would have to change that client's cogitation from the live, can allocate' mode to the dummy, cannot allocate' mode; and because that would make the code more complex).

The main work is done in the restarter-restart-now hook. It reports the current (incomplete) plan, and then checks to see if a projection walker is running; if it is, it leaves it alone, and simply abandons the current plan run and arranges for a new run to started. If a projection walker is not running it copies all the plan walker's state (including the data-plan.pl disk file containing the plan-in-progress) to the projection walker, and sets the projection walker going.

We update .gitignore to ignore data-plan.* and data-projection.*.

---
v2: Update .gitignore too.
Use walker-globals' not walker-runvars' (which does not exist). Remove wrap damage `#' from comment.
Fix typo in commit message.
Fix several silly bugs in for-free-resources
Fix three silly bugs relating to handling of $newly_free Fix a wrong bracket syntax error in restarter-maybe-provoke-restart Properly return from queuerun-perhaps-step on RESTART;
restarter-restart-now has taken the flow of control.
Reorder operations in restarter-restart-now so as to make it work Correct some wrong log messages in restarter-restart-now Add a log message when we restart planning
Minor code layout changes
In notify-to-think, process feature-noalloc properly

---
 .gitignore     |    4 +--
 README.planner |    8 +++++
 ms-queuedaemon |  104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 112 insertions(+), 4 deletions(-)
.gitignore +2 -2
index 07b039d..bccf488 100644
@@ -18,8 +18,8 @@ publish-lock
 bisecting-sticky-branch
 [tu].*
 [tu]
-data-plan.pl
-data-plan.pl.new
+data-plan.*
+data-projection.*
 data-plan-debug-*.txt
 data-tree-lock
 tree-bisect
README.planner +8 -0
index 52f757b..b1bacd4 100644
@@ -76,6 +76,14 @@ that newly-freed resources are properly offered first to the tasks at
 the front of the queue.  ms-ownerdaemon sets all idle resources to
 allocatable at the start of each planning cycle.
 
+The planner actually sometimes runs two planning cycles: if resources
+become free while the planner is running, it will restart the planning
+cycle in an effort to get those resources into service.  But, it will
+leave the existing planning run going in a projection-only mode (where
+no resources actually get allocated), so that there is a report for
+the administrator showing an idea of what the system thinks may happen
+in the more distant future.
+
 
 ms-ownerdaemon and `ownd' tasks
 -------------------------------
ms-queuedaemon +102 -2

142 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#16 lore raw

PATCH v2 15/29 Plan reporting: Break out return-plan-to-client

In reply to Ian Jackson

We are going to want to reuse this. No functional change.

---
 ms-queuedaemon |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
ms-queuedaemon +7 -2
index d48715e..8c9af81 100755
@@ -355,11 +355,16 @@ proc cmd/thought-done {chan desc} {
     puts-chan $chan "OK thought"
 }
 
+proc return-plan-to-client {chan wf} {
+    set tplan [exec -keepnewline ./ms-planner -w$wf get-plan < /dev/null]
+    puts-chan-data $chan "OK get-plan" $tplan
+    return $tplan
+}
+
 proc cmd/get-plan {chan desc} {
     global plan
     set w [check-we-are-thinking $chan]
-    set plan [exec -keepnewline ./ms-planner -w$w get-plan < /dev/null]
-    puts-chan-data $chan "OK get-plan" $plan
+    set plan [return-plan-to-client $chan $w]
 }
 
 proc cmd/book-resources {chan desc bytes} {
Signature · 1 line
1.7.10.4
#17 lore raw

PATCH v2 16/29 Plan reporting: Provide get-last-plan queuedaemon command

In reply to Ian Jackson

This allows retrieval, by monitoring clients which are not participating in the planning queue, of the finished projection, or the unfinished plan as it was at the time of last restart.

---
v2: Fix invocation of return-plan-to-client.
Use data-W.final.pl, not data-W-final.pl, to fit
with existing .gitignore, and be slightly neater.

---
 README.planner |   11 +++++++++++
 ms-queuedaemon |    8 ++++++++
 2 files changed, 19 insertions(+)
README.planner +11 -0
index b1bacd4..21b3415 100644
@@ -224,6 +224,17 @@ ms-queuedaemon commands
 
 	> thought-done | thought-wait
 
+        > get-last-plan projection|plan
+                Retrieve the last fully completed plan (`projection'),
+		or the most recent short-term information used for
+		actual resource allocation (`plan').
+
+		For monitoring tools, not participants in the resource
+		allocation process.  Response is as for get-plan:
+
+		< OK get-plan BYTES
+		PLAN-DATA
+
 
 Plan is:
 	Start	time_t used for "now" *
ms-queuedaemon +8 -0
index 8c9af81..18d703e 100755
@@ -293,6 +293,7 @@ proc report-plan {w wo} {
     } emsg]} {
         log "INTERNAL ERROR showing $w html: $emsg"
     } else {
+	file copy -force data-$w.pl data-$wo.final.pl
         log "$w report-plan OK"
     }
 }
@@ -367,6 +368,13 @@ proc cmd/get-plan {chan desc} {
     set plan [return-plan-to-client $chan $w]
 }
 
+proc cmd/get-last-plan {chan desc w} {
+    global walkers
+    if {[lsearch -exact $walkers $w] < 0} { error "unknown last-plan ($w)" }
+    if {![file exists data-$w.final.pl]} { error "no last-plan $w" }
+    return-plan-to-client $chan $w.final
+}
+
 proc cmd/book-resources {chan desc bytes} {
     read-chan-data $chan $bytes do-book-resources
 }
Signature · 1 line
1.7.10.4
#18 lore raw

PATCH v2 17/29 Planner: ms-queuedaemon: Break out chan-plan-info

In reply to Ian Jackson

Also, refactor the space separator handling to use a list and `join' (since we are going to maybe have desc be "").

---
v2: New patch

---
 ms-queuedaemon |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
ms-queuedaemon +8 -2
index 18d703e..72e22d0 100755
@@ -375,14 +375,20 @@ proc cmd/get-last-plan {chan desc w} {
     return-plan-to-client $chan $w.final
 }
 
+proc chan-plan-info {chan desc} {
+    set l {}
+    lappend l [chan-get-info $chan {"$info(preinfo)"} ""]
+    lappend l [chan-get-info $chan {"job $info(job)"} $desc]
+    return [join $l " "]
+}
+
 proc cmd/book-resources {chan desc bytes} {
     read-chan-data $chan $bytes do-book-resources
 }
 proc do-book-resources {chan desc data} {
     global plan errorInfo
     set w [check-we-are-thinking $chan]
-    set info [chan-get-info $chan {"$info(preinfo) "} ""]
-    append info [chan-get-info $chan {"job $info(job)"} $desc]
+    set info [chan-plan-info $plan $desc]
     if {[catch {
 	exec ./ms-planner -w$w book-resources $info << $data
     } emsg]} {
Signature · 1 line
1.7.10.4
#19 lore raw

PATCH v2 18/29 Planner: Report unprocessed planning clients

In reply to Ian Jackson

With recent changes, it can happen that a queue daemon client is not given an opportunity to report itself in the plan. This makes the plan incomplete.

(For resource-plan.html, because the planning run was restarted to try to quickly allocate new resources; for resource-projection.html, because it's an old client that doesn't support feature-noalloc.)

When this happens, provide an explicit indication of this in the plan:

* Invent a new entry Unprocessed in data-*.pl for this information.
* Display the first 50 in ms-planner show-html.
* Provide a new ms-planner invocation `unprocessed' to record one.
* Note unprocessed when we skip a client due to !feature-noalloc.
* Note unprocessed for remaining queue when we restart planning.

For now this algorithm can be rather unfortunately O(n^2) when draining the planning queue, because each `ms-planner unprocessed' invocation adds only one job but needs to read and write the whole
plan. This will be fixed shortly.

---
v2: New patch

---
 ms-planner     |   27 +++++++++++++++++++++++++++
 ms-queuedaemon |   10 ++++++++++
 2 files changed, 37 insertions(+)
ms-planner +27 -0
index 053f330..495c8ff 100755
@@ -238,6 +238,7 @@ sub cmd_reset () {
 
     $plan->{Start}= time;
     $plan->{Events}= { };
+    $plan->{Unprocessed}= [ ];
 
     my %magictask;
     foreach my $taskrefkey (qw(preparing shared)) {
@@ -731,12 +732,38 @@ sub cmd_show_html () {
 	printf "</tr>\n";
     }
     printf "</table>\n";
+    printf "<p>\n";
+    my $unprocessed = $plan->{Unprocessed};
+    if (@$unprocessed) {
+	    printf "%d tasks not processed and therefore not shown:\n",
+	        scalar @$unprocessed;
+	    my $shown = 0;
+	    printf "<ul>\n";
+	    foreach my $unprocessed (@$unprocessed) {
+		if (++$shown > 50) {
+		    printf "<li>...</li>\n";
+		    last;
+		}
+		printf "<li>%s</li>\n", encode_entities($unprocessed->{Info});
+	    }
+	    printf "</ul>\n";
+	    printf "<p>\n";
+    }
     printf "Report generated %s.\n",
         strftime("%Y-%b-%d %a %H:%M:%S", localtime $now);
     die $! if STDOUT->error;
     die $! unless STDOUT->flush;
 }
 
+sub cmd_unprocessed () {
+    die unless @ARGV==1;
+    my ($baseinfo) = @ARGV;
+
+    get_current_plan();
+    push @{ $plan->{Unprocessed} }, { Info => $baseinfo };
+    check_write_new_plan();
+}
+
 die unless @ARGV;
 die if $ARGV[0] =~ m/^-/;
 my $subcmd= shift @ARGV;
ms-queuedaemon +10 -0
index 72e22d0..fba28a1 100755
@@ -482,12 +482,21 @@ proc restarter-restart-now {} {
 	log-event "restarter-restart-now projection-running"
     }
 
+    foreach skip [set plan/queue_running] {
+	for-chan $skip {
+	    chan-note-unprocessed plan $skip
+	}
+    }
     report-plan plan plan
 
     unset plan/queue_running
     runneeded-ensure-will 2
 }
 
+proc chan-note-unprocessed {w chan} {
+    exec ./ms-planner -w$w unprocessed [chan-plan-info $chan {}]
+}
+
 proc notify-to-think {w thinking} {
     for-chan $thinking {
 	set noalloc [chan-get-info $thinking {$info(feature-noalloc)} {}]
@@ -496,6 +505,7 @@ proc notify-to-think {w thinking} {
 	    projection.1 { puts-chan $thinking "!OK think noalloc" }
 	    projection.* {
 		# oh well, can't include it in the projection; too bad
+		chan-note-unprocessed $w $thinking
 		queuerun-step-done $w "!feature-noalloc"
 	    }
 	}
Signature · 1 line
1.7.10.4
#20 lore raw

PATCH v2 19/29 Tcl: Provide get-chan-desc in daemonlib

In reply to Ian Jackson

Provide a facility for the daemon main program to get the channel connection information.

No caller yet.

---
v2: New patch

---
 tcl/daemonlib.tcl |    5 +++++
 1 file changed, 5 insertions(+)
tcl/daemonlib.tcl +5 -0
index d097624..55bc385 100644
@@ -106,6 +106,11 @@ proc puts-chan-desc {chan m} {
     log "$desc $m"
 }
 
+proc get-chan-desc {chan} {
+    upvar \#0 chandesc($chan) desc
+    return $desc
+}
+
 proc must-gets-chan {chan re} {
     if {[gets $chan l] <= 0} { error "NOT $chan $re ?" }
     puts-chan-desc $chan "<< $l"
Signature · 1 line
1.7.10.4
#21 lore raw

PATCH v2 20/29 Planner: ms-queuedaemon: Use chan-get-desc in chan-plan-info

In reply to Ian Jackson

This relieves the callers of the need to provide a desc. This is helpful because chan-note-unprocessed doesn't have one.

Overall functional change is to show the chan desc (ie, the client TCP connection info) in the list of unprocessed clients.

---
v2: New patch

---
 ms-queuedaemon |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
ms-queuedaemon +4 -3
index fba28a1..29b906f 100755
@@ -375,7 +375,8 @@ proc cmd/get-last-plan {chan desc w} {
     return-plan-to-client $chan $w.final
 }
 
-proc chan-plan-info {chan desc} {
+proc chan-plan-info {chan} {
+    set desc [get-chan-desc $chan]
     set l {}
     lappend l [chan-get-info $chan {"$info(preinfo)"} ""]
     lappend l [chan-get-info $chan {"job $info(job)"} $desc]
@@ -388,7 +389,7 @@ proc cmd/book-resources {chan desc bytes} {
 proc do-book-resources {chan desc data} {
     global plan errorInfo
     set w [check-we-are-thinking $chan]
-    set info [chan-plan-info $plan $desc]
+    set info [chan-plan-info $chan]
     if {[catch {
 	exec ./ms-planner -w$w book-resources $info << $data
     } emsg]} {
@@ -494,7 +495,7 @@ proc restarter-restart-now {} {
 }
 
 proc chan-note-unprocessed {w chan} {
-    exec ./ms-planner -w$w unprocessed [chan-plan-info $chan {}]
+    exec ./ms-planner -w$w unprocessed [chan-plan-info $chan]
 }
 
 proc notify-to-think {w thinking} {
Signature · 1 line
1.7.10.4
#22 lore raw

PATCH v2 21/29 Planner: Remove O(n^2) problem from plan restart

In reply to Ian Jackson

Change `./ms-planner unprocessed' to take a file of infos on stdin, and when we restart the planning, invoke it once.

(This would be an incompatible change to the planner, needing a queuedaemon restart, if this patch were applied separately from the previous "Report unprocessed planning clients".)

---
v2: New patch

---
 ms-planner     |   10 +++++++---
 ms-queuedaemon |   18 +++++++++++-------
 2 files changed, 18 insertions(+), 10 deletions(-)
ms-planner +7 -3
index 495c8ff..47e0ea7 100755
@@ -756,11 +756,15 @@ sub cmd_show_html () {
 }
 
 sub cmd_unprocessed () {
-    die unless @ARGV==1;
-    my ($baseinfo) = @ARGV;
+    die unless @ARGV==0;
 
     get_current_plan();
-    push @{ $plan->{Unprocessed} }, { Info => $baseinfo };
+
+    while (<STDIN>) {
+	chomp;
+	push @{ $plan->{Unprocessed} }, { Info => $_ };
+    }
+
     check_write_new_plan();
 }
 
ms-queuedaemon +11 -7
index 29b906f..a249b50 100755
@@ -483,10 +483,10 @@ proc restarter-restart-now {} {
 	log-event "restarter-restart-now projection-running"
     }
 
-    foreach skip [set plan/queue_running] {
-	for-chan $skip {
-	    chan-note-unprocessed plan $skip
-	}
+    if {[catch {
+	chans-note-unprocessed plan [set plan/queue_running]
+    } emsg]} {
+	log "INTERNAL ERROR setting unprocessed: $emsg"
     }
     report-plan plan plan
 
@@ -494,8 +494,12 @@ proc restarter-restart-now {} {
     runneeded-ensure-will 2
 }
 
-proc chan-note-unprocessed {w chan} {
-    exec ./ms-planner -w$w unprocessed [chan-plan-info $chan]
+proc chans-note-unprocessed {w chans} {
+    set data {}
+    foreach chan $chans {
+	append data [chan-plan-info $chan] "\n"
+    }
+    exec ./ms-planner -w$w unprocessed << $data
 }
 
 proc notify-to-think {w thinking} {
@@ -506,7 +510,7 @@ proc notify-to-think {w thinking} {
 	    projection.1 { puts-chan $thinking "!OK think noalloc" }
 	    projection.* {
 		# oh well, can't include it in the projection; too bad
-		chan-note-unprocessed $w $thinking
+		chans-note-unprocessed $w [list $thinking]
 		queuerun-step-done $w "!feature-noalloc"
 	    }
 	}
Signature · 1 line
1.7.10.4
#23 lore raw

PATCH v2 22/29 Planner: ms-queuedaemon: Better log message for Tcl `after idle'

In reply to Ian Jackson

This does not mean the planner is `idle' in any general sense of the word. It just means that the Tcl event loop has finished processing outstanding events. Change the debug message to be less confusing.

---
v2: New patch

---
 ms-queuedaemon |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ms-queuedaemon +1 -1
index a249b50..9280f51 100755
@@ -73,7 +73,7 @@ proc log-event {m} {
     if {![info exists log_state_after]} {
         set log_state_after [after idle {
             unset log_state_after
-            log-state idle
+            log-state tcl-idle
         }]
     }
 }
Signature · 1 line
1.7.10.4
#24 lore raw

PATCH v2 23/29 Planner: ms-queuedaemon: Reformat debugging output for more tasks

In reply to Ian Jackson

These wider fields will work well for up to 999 tasks.

Cosmetic change only.

---
v2: New patch

---
 ms-queuedaemon |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
ms-queuedaemon +7 -6
index 9280f51..98cf5c1 100755
@@ -81,20 +81,21 @@ proc log-event {m} {
 proc log-state {m} {
     global need_queue_run queue
 
-    set lhs [format "N=%d Q=%d (%-11.11s) " \
+    set lhs [format "N=%d Q=%d (%-15.15s) " \
                  $need_queue_run [llength $queue] $queue]
 
     foreach-walker w {
+	append lhs "| "
 	if {[info exists queue_running]} {
-	    append lhs [format "R=%d " [llength $queue_running]]
+	    append lhs [format "R=%-3d " [llength $queue_running]]
 	    if {[info exists thinking]} {
-		append lhs [format "T=%s " $thinking]
+		append lhs [format "T=%-7s " $thinking]
 	    } else {
-		append lhs [format "        "]
+		append lhs [format "          "]
 	    }
-	    append lhs [format "(%-11.11s) " $queue_running]
+	    append lhs [format "(%-15.15s) " $queue_running]
 	} else {
-	    append lhs "                          "
+	    append lhs "                                  "
 	}
     }
 
Signature · 1 line
1.7.10.4
#25 lore raw

PATCH v2 24/29 Manual allocation: Report better info in plan for rogue tasks

In reply to Ian Jackson

(This will only take effect as such tasks appear in the plan for the first time. Ie, once a rogue task is found, the plan is populated by whatever version of the planner is running at that time. So the effect will not be immediately visible.)

---
v2: New patch

---
 ms-planner |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
ms-planner +4 -1
index 47e0ea7..1f996a6 100755
@@ -291,7 +291,10 @@ END
 	    $info= "(preparing)";
 	} else {
 	    print DEBUG "rogue $reso $shareix: $arow->{owntaskid}\n";
-	    $info= "rogue task $arow->{subtask}";
+	    $info= "rogue task";
+	    $info .= " $arow->{type} $arow->{refkey}";
+	    $info .= " ($arow->{comment})" if defined $arow->{comment};
+	    $info .= " $arow->{subtask}";
 	}
 	$plan->{Allocations}{$reskey}= {
             Task => $arow->{owntaskid},
Signature · 1 line
1.7.10.4
#26 lore raw

PATCH v2 25/29 Manual allocation: Break out manual_allocation_base_jobinfo from mg-blockage

In reply to Ian Jackson

This is called `jobinfo' because it ought to be used in alloc_resources's JobInfo xparam, rather than an Xinfo in the booking:
JobInfo is per planning client; Xinfo is per individual resource.

mg-blockage currently gets this wrong; we will fix that shortly.

---
v2: New patch

---
 Osstest/Executive.pm |    7 +++++++
 mg-blockage          |    5 ++---
 2 files changed, 9 insertions(+), 3 deletions(-)
Osstest/Executive.pm +7 -0
index 4f51d70..1efcfd4 100644
@@ -51,6 +51,7 @@ BEGIN {
                       report_altchangecolour
                       report_blessingscond report_find_push_age_info
                       tcpconnect_queuedaemon plan_search
+                      manual_allocation_base_jobinfo
                       alloc_resources alloc_resources_rollback_begin_work
                       resource_check_allocated resource_shared_mark_ready
                       duration_estimator
@@ -494,6 +495,12 @@ END
     return $taskid;
 }        
 
+sub manual_allocation_base_jobinfo () {
+    my $whoami = `whoami`; chomp $whoami;
+    my $hostname = `uname -n`; chomp $hostname;
+    return "$whoami\@$hostname";
+}
+
 sub alloc_resources_rollback_begin_work () {
     $dbh_tests->rollback();
     db_begin_work($dbh_tests, \@all_lock_tables);
mg-blockage +2 -3
index 1f66d8e..0286c27 100755
@@ -24,9 +24,8 @@ sub parsedate ($) {
     return $r;
 }
 
-my $whoami = `whoami`; chomp $whoami;
-my $hostname = `uname -n`; chomp $hostname;
-my $xinfo = "blockage $whoami\@$hostname [$start .. $end]";
+my $basexinfo = manual_allocation_base_joinfo();
+my $xinfo = "blockage $basexinfo [$start .. $end]";
 $xinfo .= " $mxinfo" if defined $mxinfo;
 
 $start = parsedate $start;
Signature · 1 line
1.7.10.4
#27 lore raw

Re: [OSSTEST PATCH 25/29] Manual allocation: Break out manual_allocation_base_jobinfo from mg-blockage

Quoted 46 lines · Ian Jackson

This is called `jobinfo' because it ought to be used in alloc_resources's JobInfo xparam, rather than an Xinfo in the booking:
JobInfo is per planning client; Xinfo is per individual resource.

mg-blockage currently gets this wrong; we will fix that shortly.

---
v2: New patch

---
 Osstest/Executive.pm |    7 +++++++
 mg-blockage          |    5 ++---
 2 files changed, 9 insertions(+), 3 deletions(-)
Osstest/Executive.pm +1 -0
index 4f51d70..1efcfd4 100644
@@ -51,6 +51,7 @@ BEGIN {
                       report_altchangecolour
                       report_blessingscond report_find_push_age_info
                       tcpconnect_queuedaemon plan_search
+                      manual_allocation_base_jobinfo
                       alloc_resources

alloc_resources_rollback_begin_work
resource_check_allocated
resource_shared_mark_ready
duration_estimator

Osstest/Executive.pm +6 -0
@@ -494,6 +495,12 @@ END
     return $taskid;
 }        
 
+sub manual_allocation_base_jobinfo () {
+    my $whoami = `whoami`; chomp $whoami;
+    my $hostname = `uname -n`; chomp $hostname;
+    return "$whoami\@$hostname";
+}
+
 sub alloc_resources_rollback_begin_work () {
     $dbh_tests->rollback();
     db_begin_work($dbh_tests, \@all_lock_tables);
mg-blockage +0 -0
index 1f66d8e..0286c27 100755

mg-blockage sub parsedate ($) { · line 27

Quoted 7 lines
mg-blockage +1 -3
@@ -24,9 +24,8 @@ sub parsedate ($) {
     return $r;
 }
 
-my $whoami = `whoami`; chomp $whoami;
-my $hostname = `uname -n`; chomp $hostname;
-my $xinfo = "blockage $whoami\@$hostname [$start .. $end]";
+my $basexinfo = manual_allocation_base_joinfo();

missing a b in jobinfo I think.

Quoted 4 lines
mg-blockage +1 -0
+my $xinfo = "blockage $basexinfo [$start .. $end]";
 $xinfo .= " $mxinfo" if defined $mxinfo;
 
 $start = parsedate $start;
#28 lore raw

PATCH v2 26/29 Manual allocation: Provide JobInfo in mg-blockage

In reply to Ian Jackson

Supply most of the information about our allocations in JobInfo, rather than Xinfo. And, correspondingly, rename all the variables xinfo' to info'.

Supply only the supplied hostname as the Xinfo. This is slightly redundant but it does at least tell us what came out of the db.

---
v2: New patch

---
 mg-blockage |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
mg-blockage +7 -7
index 0286c27..90547a5 100755
@@ -14,7 +14,7 @@ csreadconfig();
 die unless @ARGV==3 || @ARGV==4;
 die if $ARGV[0] =~ m/^=/;
 
-our ($start,$end,$hostflag,$mxinfo) = @ARGV;
+our ($start,$end,$hostflag,$minfo) = @ARGV;
 
 sub parsedate ($) {
     open D, "-|", qw(date +%s -d), @_ or die $!;
@@ -24,13 +24,13 @@ sub parsedate ($) {
     return $r;
 }
 
-my $basexinfo = manual_allocation_base_joinfo();
-my $xinfo = "blockage $basexinfo [$start .. $end]";
-$xinfo .= " $mxinfo" if defined $mxinfo;
+my $baseinfo = manual_allocation_base_jobinfo();
+my $info = "blockage $baseinfo [$start .. $end]";
+$info .= " $minfo" if defined $minfo;
 
 $start = parsedate $start;
 $end   = parsedate $end;
-print $xinfo, "\n" or die $!;
+print $info, "\n" or die $!;
 
 die unless $end > $start;
 
@@ -38,7 +38,7 @@ sub min { (sort @_)[0]; }
 sub max { (reverse sort @_)[0]; }
 
 sub plan () {
-    alloc_resources(sub {
+    alloc_resources(JobInfo => $info, sub {
 	my ($plan, $mayalloc) = @_;
 
 	my $now = time;
@@ -72,7 +72,7 @@ END
 		foreach (my $ix=0; $ix<$avail; $ix++) {
 		    my $booking =  {
 			Reso => $res->{restype}.' '.$res->{resname},
-			Xinfo => $xinfo,
+			Xinfo => $host,
 			Start => $bookstart - $now,
 			End => $bookend - $now,
 		    };
Signature · 1 line
1.7.10.4
#29 lore raw

PATCH v2 27/29 Manual allocation: Provide JobInfo in mg-allocate

In reply to Ian Jackson

Use manual_allocation_base_jobinfo to obtain some information which will go into `job' in the planner, and show up everywhere.

Put just the request (from the command line) in the Xinfo.

---
v2: New patch

---
 mg-allocate |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
mg-allocate +5 -2
index 14c9088..672d9ec 100755
@@ -269,7 +269,10 @@ sub showposs ($) {
 
 sub plan () {
     my @got;
-    alloc_resources(sub {
+
+    my $info = "manual ".manual_allocation_base_jobinfo();
+
+    alloc_resources(JobInfo => $info, sub {
         my ($plan, $mayalloc) = @_;
 
 	@got = ();
@@ -337,7 +340,7 @@ sub plan () {
         foreach my $req (@reqlist) {
             my $book= {
                 Reso => $req->{Reso},
-                Xinfo => "manual",
+                Xinfo => $req->{Ident},
                 Start => $planned->{Start},
                 End => $planned->{Start} + $duration,
             };
Signature · 1 line
1.7.10.4
#30 lore raw

PATCH v2 28/29 Manual allocation: Show tty in jobinfo

In reply to Ian Jackson

---
v2: New patch

---
 Osstest/Executive.pm |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Osstest/Executive.pm +4 -1
index 1efcfd4..84600b4 100644
@@ -498,7 +498,10 @@ END
 sub manual_allocation_base_jobinfo () {
     my $whoami = `whoami`; chomp $whoami;
     my $hostname = `uname -n`; chomp $hostname;
-    return "$whoami\@$hostname";
+    my $info = "$whoami\@$hostname";
+    my $tty = `tty 2>/dev/null`; chomp $tty;
+    $info .= " ($tty)" unless $?;
+    return $info;
 }
 
 sub alloc_resources_rollback_begin_work () {
Signature · 1 line
1.7.10.4
#31 lore raw

PATCH v2 29/29 Manual allocation: Set $| in mg-blockage

In reply to Ian Jackson

This makes it slightly easier to see what it's happening if mg-allocate or mg-blockage has no tty.

---
v2: New patch

---
 mg-allocate |    2 ++
 mg-blockage |    2 ++
 2 files changed, 4 insertions(+)
mg-allocate +2 -0
index 672d9ec..1e517a2 100755
@@ -36,6 +36,8 @@ use Osstest::Executive;
 
 csreadconfig();
 
+$|=1;
+
 our $tid;
 our %magictask;
 
mg-blockage +2 -0
index 90547a5..d3e6169 100755
@@ -24,6 +24,8 @@ sub parsedate ($) {
     return $r;
 }
 
+$|=1;
+
 my $baseinfo = manual_allocation_base_jobinfo();
 my $info = "blockage $baseinfo [$start .. $end]";
 $info .= " $minfo" if defined $minfo;
Signature · 1 line
1.7.10.4