aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-05-09 20:38:02 +0100
committerChristopher Baines <mail@cbaines.net>2020-05-09 20:38:02 +0100
commitab86dd62a77f59a73360bf85a2ba89405c352153 (patch)
tree97ca340c22a66aaa17eca79ad32540879afa3541
parent4f09a15fad7b4787ab7a3a14d1af42b6cda115b7 (diff)
downloadbuild-coordinator-ab86dd62a77f59a73360bf85a2ba89405c352153.tar
build-coordinator-ab86dd62a77f59a73360bf85a2ba89405c352153.tar.gz
Stop base64 encoding chunked requests
I'm not sure why I did this... but it's slower and more complex than just not base64 encoding the data.
-rw-r--r--guix-build-coordinator/agent-messaging/http.scm48
-rw-r--r--guix-build-coordinator/utils.scm21
2 files changed, 27 insertions, 42 deletions
diff --git a/guix-build-coordinator/agent-messaging/http.scm b/guix-build-coordinator/agent-messaging/http.scm
index 9e60b4a..40d6653 100644
--- a/guix-build-coordinator/agent-messaging/http.scm
+++ b/guix-build-coordinator/agent-messaging/http.scm
@@ -321,12 +321,10 @@ port. Also, the port used can be changed by passing the --port option.\n"
(lambda ()
(call-with-output-file output-file-name
(lambda (output-port)
- (let loop ((line (get-line body)))
- (unless (eof-object? line)
- (base64-decode line
- base64-alphabet
- output-port)
- (loop (get-line body))))))
+ (let loop ((bv (get-bytevector-some body)))
+ (unless (eof-object? bv)
+ (put-bytevector output-port bv)
+ (loop (get-bytevector-some body))))))
#t))
(no-content)
(render-json
@@ -348,48 +346,44 @@ port. Also, the port used can be changed by passing the --port option.\n"
(call-with-output-file output-file-name
(lambda (output-port)
(let ((start-time (current-time time-utc)))
- (let loop ((line (get-line body))
- (base64-characters-read 0)
- (last-progress-update-characters-read 0))
- (if (eof-object? line)
+ (let loop ((bv (get-bytevector-some body))
+ (bytes-read 0)
+ (last-progress-update-bytes-read 0))
+ (if (eof-object? bv)
(let* ((end-time (current-time time-utc))
(elapsed (time-difference end-time
start-time))
(seconds-elapsed
(+ (time-second elapsed)
- (/ (time-nanosecond elapsed) 1e9)))
- (bytes-transfered
- (* 3 (/ base64-characters-read 4))))
+ (/ (time-nanosecond elapsed) 1e9))))
(display
(simple-format
#f
"receiving ~A\n took ~A seconds\n data transfered: ~AMB\n speed (MB/s): ~A\n"
(basename output-file-name)
seconds-elapsed
- (rationalize (exact->inexact (/ bytes-transfered 1000000))
+ (rationalize (exact->inexact (/ bytes-read 1000000))
0.1)
- (rationalize (/ (/ bytes-transfered 1000000) seconds-elapsed)
+ (rationalize (/ (/ bytes-read 1000000) seconds-elapsed)
0.1))))
(begin
- (base64-decode line
- base64-alphabet
- output-port)
- (loop (get-line body)
- (+ base64-characters-read
- (string-length line))
- (if (> (- base64-characters-read
- last-progress-update-characters-read)
- 66666666) ; ~50MB in base64 characters
+ (put-bytevector output-port bv)
+ (loop (get-bytevector-some body)
+ (+ bytes-read
+ (bytevector-length bv))
+ (if (> (- bytes-read
+ last-progress-update-bytes-read)
+ 50000000) ; ~50MB
(begin
(display
(simple-format
#f "receiving ~A\n ~AMB read so far...\n"
(basename output-file-name)
- (rationalize (exact->inexact (/ (* 3 (/ base64-characters-read 4))
+ (rationalize (exact->inexact (/ bytes-read
1000000))
0.1)))
- base64-characters-read)
- last-progress-update-characters-read))))))))
+ bytes-read)
+ last-progress-update-bytes-read))))))))
#t))
(no-content)
(render-json
diff --git a/guix-build-coordinator/utils.scm b/guix-build-coordinator/utils.scm
index 1dd4cbf..1e34df7 100644
--- a/guix-build-coordinator/utils.scm
+++ b/guix-build-coordinator/utils.scm
@@ -268,27 +268,18 @@ upcoming chunk."
#:port port)))
(let ((request (write-request request port)))
- (let* ((chunked-output-port
- (make-chunked-output-port
- port
- ;; The number of bytes produced when the base64 port flushes
- ;; it's buffer
- #:buffering (let ((lines 65536)
- (line-length 72))
- (- (* (+ line-length 1)
- lines)
- 1))
- #:keep-alive? #t))
- (base64-output-port
- (make-base64-output-port chunked-output-port)))
+ (let ((chunked-output-port
+ (make-chunked-output-port
+ port
+ #:buffering (expt 2 20)
+ #:keep-alive? #t)))
;; A SIGPIPE will kill Guile, so ignore it
(sigaction SIGPIPE
(lambda (arg)
(simple-format (current-error-port) "warning: SIGPIPE\n")))
- (callback base64-output-port)
- (close-port base64-output-port)
+ (callback chunked-output-port)
(close-port chunked-output-port)
(display "\r\n" port)
(force-output port))