unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] offload: Memoize the 'machine-load' procedure
@ 2015-06-17 18:28 Mark H Weaver
  2015-06-17 19:28 ` Ludovic Courtès
  0 siblings, 1 reply; 2+ messages in thread
From: Mark H Weaver @ 2015-06-17 18:28 UTC (permalink / raw)
  To: guix-devel

[-- Attachment #1: Type: text/plain, Size: 343 bytes --]

This patch memoizes the 'machine-load' procedure so that the load of
each build slave is queried only once per call to 'guix offload'.  Apart
from avoiding wasteful repeated ssh connections, this is needed to
ensure that all calls to the sorting predicate are consistent with each
other, which is part of the contract with 'sort'.

     Mark


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: [PATCH] offload: Memoize the 'machine-load' procedure --]
[-- Type: text/x-patch, Size: 3135 bytes --]

From 1fa02a0b0f50e141935833f6dfc295f654118621 Mon Sep 17 00:00:00 2001
From: Mark H Weaver <mhw@netris.org>
Date: Wed, 17 Jun 2015 13:58:00 -0400
Subject: [PATCH] offload: Memoize the 'machine-load' procedure.

* guix/scripts/offload.scm (machine-load): Memoize.
---
 guix/scripts/offload.scm | 46 ++++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/guix/scripts/offload.scm b/guix/scripts/offload.scm
index e6be8b4..0956f1a 100644
--- a/guix/scripts/offload.scm
+++ b/guix/scripts/offload.scm
@@ -531,30 +531,32 @@ success, #f otherwise."
                (build-requirements-features requirements)
                (build-machine-features machine))))
 
-(define (machine-load machine)
-  "Return the load of MACHINE, divided by the number of parallel builds
+(define machine-load
+  (memoize
+   (lambda (machine)
+     "Return the load of MACHINE, divided by the number of parallel builds
 allowed on MACHINE."
-  (let* ((pipe   (remote-pipe machine OPEN_READ `("cat" "/proc/loadavg")))
-         (line   (read-line pipe))
-         (status (close-pipe pipe)))
-    (unless (eqv? 0 (status:exit-val status))
-      (warning (_ "failed to obtain load of '~a': SSH client exited with ~a~%")
-               (build-machine-name machine)
-               (status:exit-val status)))
-
-    (if (eof-object? line)
-        +inf.0    ;MACHINE does not respond, so assume it is infinitely loaded
-        (match (string-tokenize line)
-          ((one five fifteen . _)
-           (let* ((raw        (string->number five))
-                  (jobs       (build-machine-parallel-builds machine))
-                  (normalized (/ raw jobs)))
-             (format (current-error-port) "load on machine '~a' is ~s\
+     (let* ((pipe   (remote-pipe machine OPEN_READ `("cat" "/proc/loadavg")))
+            (line   (read-line pipe))
+            (status (close-pipe pipe)))
+       (unless (eqv? 0 (status:exit-val status))
+         (warning (_ "failed to obtain load of '~a': SSH client exited with ~a~%")
+                  (build-machine-name machine)
+                  (status:exit-val status)))
+
+       (if (eof-object? line)
+           +inf.0  ;MACHINE does not respond, so assume it is infinitely loaded
+           (match (string-tokenize line)
+             ((one five fifteen . _)
+              (let* ((raw        (string->number five))
+                     (jobs       (build-machine-parallel-builds machine))
+                     (normalized (/ raw jobs)))
+                (format (current-error-port) "load on machine '~a' is ~s\
  (normalized: ~s)~%"
-                     (build-machine-name machine) raw normalized)
-             normalized))
-          (_
-           +inf.0)))))           ;something's fishy about MACHINE, so avoid it
+                        (build-machine-name machine) raw normalized)
+                normalized))
+             (_
+              +inf.0)))))))       ;something's fishy about MACHINE, so avoid it
 
 (define (machine-power-factor m)
   "Return a factor that aggregates the speed and load of M.  The higher the
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] offload: Memoize the 'machine-load' procedure
  2015-06-17 18:28 [PATCH] offload: Memoize the 'machine-load' procedure Mark H Weaver
@ 2015-06-17 19:28 ` Ludovic Courtès
  0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2015-06-17 19:28 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guix-devel

Mark H Weaver <mhw@netris.org> skribis:

> This patch memoizes the 'machine-load' procedure so that the load of
> each build slave is queried only once per call to 'guix offload'.  Apart
> from avoiding wasteful repeated ssh connections, this is needed to
> ensure that all calls to the sorting predicate are consistent with each
> other, which is part of the contract with 'sort'.

Good point.

I don’t think we can memoize it globally.  The reason is that
‘choose-build-machine’ can return #f when all the machines are
overloaded; in that case ‘guix offload’ returns “postpone”, and doesn’t
exit.  Instead, it tries again until at least one machine is not
overloaded.

So I think we should memoize ‘machine-less-loaded-or-faster?’ locally in
‘choose-build-machine’.

WDYT?

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-06-17 19:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-17 18:28 [PATCH] offload: Memoize the 'machine-load' procedure Mark H Weaver
2015-06-17 19:28 ` Ludovic Courtès

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).