@@ -61,38 +61,27 @@ test-name item-path jobgroup waitons testmode newtal itemmaps prereqs-not-met) ;; Fourth try, do accounting through time ;; -(define (runs:parallel-runners-mgmt-4 rdat) - (let ((time-to-check 2.8) ;; 28 - (time-to-wait 3.0) +(define (runs:parallel-runners-mgmt rdat) + (let ((time-to-check 10) ;; 28 + (time-to-wait 12) (now-time (current-seconds))) (if (> (- now-time (runs:dat-last-fuel-check rdat)) time-to-check) ;; time to check - (let* ((mgmt-mode (runs:dat-runners-mgmt-mode rdat)) ;; - (fuel-used (rmt:get-var "runners-fuel"))) + (let* ((fuel-used (or (rmt:get-var "runners-fuel") now-time))) ;; initialize and sanitize values if needed - (cond - ((not fuel-used) ;; first in, initialize to 1 - (debug:print-info 0 *default-log-port* " adjusting num-runners up to 1, currently it is not defined") - (rmt:set-var "fuel-used" now-time) - (set! fuel-used now-time) - (runs:dat-last-fuel-check-set! rdat now-time)) - (else ;; add fuel used since last time - (rmt:add-var "fuel-used" (- now-time (runs:dat-last-fuel-check rdat))))) - - (if (> fuel-used now-time) ;; are we over-drawn? If so, kill time, do not add time to fuel used - (begin ;; gonna rest - (debug:print-info 0 *default-log-port* "Too much fuel used, taking a break. fuel-used=" - fuel-used ", now-time=" now-time) - (thread-sleep! time-to-wait) - (runs:dat-last-fuel-check-set! rdat (current-seconds)) ;; work done from here (i.e. seconds of "fuel") will be added to fuel-used - ) - (begin ;; no fuel deficit, back to work - (debug:print-info 0 *default-log-port* "No deficit, keep running")) - ))))) - + (if (> fuel-used (+ now-time 1)) ;; are we over-drawn? If so, kill time, do not add time to fuel used + (begin ;; gonna rest + (debug:print-info 0 *default-log-port* "Runner load high, taking a break.") + (thread-sleep! time-to-wait) + (runs:dat-last-fuel-check-set! rdat (current-seconds)) ;; work done from here (i.e. seconds of "fuel") will be added to fuel-used + ) + (begin ;; no fuel deficit, back to work + (rmt:set-var "runners-fuel" (+ now-time time-to-check)) + )))))) + ;; To test parallel-runners management start a repl: ;; megatest -repl ;; then run: ;; (runs:test-parallel-runners 60) ;; @@ -99,20 +88,20 @@ (define (runs:test-parallel-runners duration #!optional (proc #f)) (let* ((rdat (make-runs:dat)) (rtime 0) (startt (current-seconds)) (endt (+ startt duration))) - ((or proc runs:parallel-runners-mgmt-4) rdat) + ((or proc runs:parallel-runners-mgmt) rdat) (let loop () (let* ((wstart (current-seconds))) (if (< wstart endt) (let* ((work-time (random 10))) #;(debug:print-info 0 *default-log-port* "working for " work-time " seconds. Total work: " rtime ", elapsed time: " (- wstart startt)) (thread-sleep! work-time) (set! rtime (+ rtime work-time)) - ((or proc runs:parallel-runners-mgmt-4) rdat) + ((or proc runs:parallel-runners-mgmt) rdat) (loop))))) (let* ((done-time (current-seconds))) (debug:print-info 0 *default-log-port* "DONE: rtime=" rtime ", elapsed time=" (- done-time startt) ", ratio=" (/ rtime (- done-time startt))))))