unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: guix-devel@gnu.org
Subject: [PATCH] offload: Memoize the 'machine-load' procedure
Date: Wed, 17 Jun 2015 14:28:08 -0400	[thread overview]
Message-ID: <87pp4udwav.fsf@netris.org> (raw)

[-- 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


             reply	other threads:[~2015-06-17 18:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-17 18:28 Mark H Weaver [this message]
2015-06-17 19:28 ` [PATCH] offload: Memoize the 'machine-load' procedure Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pp4udwav.fsf@netris.org \
    --to=mhw@netris.org \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).