aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator/agent-messaging/http.scm
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2021-11-20 21:00:46 +0000
committerChristopher Baines <mail@cbaines.net>2021-11-20 21:00:46 +0000
commit3f53272c37968a7b1b5c746ad158aa7fc718ca53 (patch)
tree4c37a59de7833e76c75ddca220d647122a61ade0 /guix-build-coordinator/agent-messaging/http.scm
parent893d8eec6659610f18c00e9996afec81c96e1592 (diff)
downloadbuild-coordinator-3f53272c37968a7b1b5c746ad158aa7fc718ca53.tar
build-coordinator-3f53272c37968a7b1b5c746ad158aa7fc718ca53.tar.gz
Compress outputs outside of the upload slot
So that the only thing taking place in the upload slot, is the actual upload, which should improve throughput.
Diffstat (limited to 'guix-build-coordinator/agent-messaging/http.scm')
-rw-r--r--guix-build-coordinator/agent-messaging/http.scm94
1 files changed, 38 insertions, 56 deletions
diff --git a/guix-build-coordinator/agent-messaging/http.scm b/guix-build-coordinator/agent-messaging/http.scm
index ac45ca3..6f87426 100644
--- a/guix-build-coordinator/agent-messaging/http.scm
+++ b/guix-build-coordinator/agent-messaging/http.scm
@@ -295,63 +295,45 @@
(string-append "/build/" build-id "/output/" output-name
(if resume? "/partial" ""))))
- (define path-info
- (with-store store
- (query-path-info store file)))
-
(define (perform-upload)
- (let* ((directory (or (getenv "TMPDIR") "/tmp"))
- (template (string-append directory
- "/guix-build-coordinator-file.XXXXXX"))
- (out (mkstemp! template)))
- (log 'INFO "compressing " file " -> " template " prior to sending")
- (call-with-lzip-output-port out
- (lambda (port)
- (write-file file port))
- #:level 9)
- (close-port out)
-
- (log 'INFO "finished compressing " file ", now sending")
- (retry-on-error
- (lambda ()
- (let ((bytes (or (get-partial-upload-bytes)
- (get-completed-upload-bytes))))
- ;; Check if the server has all the bytes
- (unless (and bytes
- (eq? bytes (stat:size (stat template))))
-
- ;; Still more to send
- (call-with-input-file template
- (lambda (file-port)
- (when bytes
- (seek file-port bytes SEEK_SET)
- (log 'INFO "resuming upload from byte " bytes))
-
- (let-values (((response body)
- (call-with-streaming-http-request
- (uri #:resume? (integer? bytes))
- (lambda (port)
- (with-time-logging
- (simple-format #f "sending ~A" file)
- (dump-port file-port port
- #:buffer-size 65536)))
- #:headers `((Authorization . ,auth-value))
- #:method (if bytes 'POST 'PUT)
- #:report-bytes-sent report-bytes-sent)))
- (when (>= (response-code response) 400)
- (raise-exception
- (make-exception-with-message
- (coordinator-handle-failed-request
- log
- 'PUT
- (uri-path
- (uri #:resume? (integer? bytes)))
- response
- body))))))))))
- #:times 100
- #:delay (random 15))
-
- (delete-file template)))
+ (retry-on-error
+ (lambda ()
+ (let ((bytes (or (get-partial-upload-bytes)
+ (get-completed-upload-bytes))))
+ ;; Check if the server has all the bytes
+ (unless (and bytes
+ (eq? bytes (stat:size (stat template))))
+
+ ;; Still more to send
+ (call-with-input-file file
+ (lambda (file-port)
+ (when bytes
+ (seek file-port bytes SEEK_SET)
+ (log 'INFO "resuming upload from byte " bytes))
+
+ (let-values (((response body)
+ (call-with-streaming-http-request
+ (uri #:resume? (integer? bytes))
+ (lambda (port)
+ (with-time-logging
+ (simple-format #f "sending ~A" file)
+ (dump-port file-port port
+ #:buffer-size 65536)))
+ #:headers `((Authorization . ,auth-value))
+ #:method (if bytes 'POST 'PUT)
+ #:report-bytes-sent report-bytes-sent)))
+ (when (>= (response-code response) 400)
+ (raise-exception
+ (make-exception-with-message
+ (coordinator-handle-failed-request
+ log
+ 'PUT
+ (uri-path
+ (uri #:resume? (integer? bytes)))
+ response
+ body))))))))))
+ #:times 100
+ #:delay (random 15)))
(unless (get-completed-upload-bytes)
(perform-upload)))