diff options
| author | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2020-11-10 16:59:13 -0500 |
|---|---|---|
| committer | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2020-11-16 00:04:32 -0500 |
| commit | 630602831dd93e7bc9a8e64fba958300e8cb0474 (patch) | |
| tree | e12c2332119aeda7adacff5750b16d8214bdd127 | |
| parent | 62343288ef6dc56027d268ef773ae699a4bbb76d (diff) | |
publish: Harmonize buffer size values and configuration.
This change harmonizes the way we configure the buffer sizes and the socket
options, so that we don't forget to change it at one place like it happened in
commit 5e3d169945935b53325e6b738a307ba286751259.
* guix/scripts/publish.scm (%default-buffer-size)
(%default-socket-options): New variables.
* guix/scripts/publish.scm (configure-socket): New procedure.
(compress-nar): Use %default-buffer-size for the buffer size, increased from
128 to 208 KiB.
(nar-response-port): Likewise, increased from 64 to 208 KiB.
(http-write): Use configure-socket to set socket options.
(open-server-socket): Likewise.
| -rw-r--r-- | guix/scripts/publish.scm | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm index a976a9ac600..f1a9970a7ff 100644 --- a/guix/scripts/publish.scm +++ b/guix/scripts/publish.scm | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | ;;; Copyright © 2015 David Thompson <davet@gnu.org> | 2 | ;;; Copyright © 2015 David Thompson <davet@gnu.org> |
| 3 | ;;; Copyright © 2020 by Amar M. Singh <nly@disroot.org> | 3 | ;;; Copyright © 2020 by Amar M. Singh <nly@disroot.org> |
| 4 | ;;; Copyright © 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org> | 4 | ;;; Copyright © 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org> |
| 5 | ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com> | ||
| 5 | ;;; | 6 | ;;; |
| 6 | ;;; This file is part of GNU Guix. | 7 | ;;; This file is part of GNU Guix. |
| 7 | ;;; | 8 | ;;; |
| @@ -250,6 +251,21 @@ usage." | |||
| 250 | ("WantMassQuery" . 0) | 251 | ("WantMassQuery" . 0) |
| 251 | ("Priority" . 100))) | 252 | ("Priority" . 100))) |
| 252 | 253 | ||
| 254 | ;;; A common buffer size value used for the TCP socket SO_SNDBUF option and | ||
| 255 | ;;; the gzip compressor buffer size. | ||
| 256 | (define %default-buffer-size | ||
| 257 | (* 208 1024)) | ||
| 258 | |||
| 259 | (define %default-socket-options | ||
| 260 | ;; List of options passed to 'setsockopt' when transmitting files. | ||
| 261 | (list (list SO_SNDBUF %default-buffer-size))) | ||
| 262 | |||
| 263 | (define* (configure-socket socket #:key (level SOL_SOCKET) | ||
| 264 | (options %default-socket-options)) | ||
| 265 | "Apply multiple option tuples in OPTIONS to SOCKET, using LEVEL." | ||
| 266 | (for-each (cut apply setsockopt socket level <>) | ||
| 267 | options)) | ||
| 268 | |||
| 253 | (define (signed-string s) | 269 | (define (signed-string s) |
| 254 | "Sign the hash of the string S with the daemon's key. Return a canonical | 270 | "Sign the hash of the string S with the daemon's key. Return a canonical |
| 255 | sexp for the signature." | 271 | sexp for the signature." |
| @@ -569,7 +585,7 @@ requested using POOL." | |||
| 569 | (lambda (port) | 585 | (lambda (port) |
| 570 | (write-file item port)) | 586 | (write-file item port)) |
| 571 | #:level (compression-level compression) | 587 | #:level (compression-level compression) |
| 572 | #:buffer-size (* 128 1024)) | 588 | #:buffer-size %default-buffer-size) |
| 573 | (rename-file (string-append nar ".tmp") nar)) | 589 | (rename-file (string-append nar ".tmp") nar)) |
| 574 | ('lzip | 590 | ('lzip |
| 575 | ;; Note: the file port gets closed along with the lzip port. | 591 | ;; Note: the file port gets closed along with the lzip port. |
| @@ -866,7 +882,7 @@ or if EOF is reached." | |||
| 866 | ;; 'make-gzip-output-port' wants a file port. | 882 | ;; 'make-gzip-output-port' wants a file port. |
| 867 | (make-gzip-output-port (response-port response) | 883 | (make-gzip-output-port (response-port response) |
| 868 | #:level level | 884 | #:level level |
| 869 | #:buffer-size (* 64 1024))) | 885 | #:buffer-size %default-buffer-size)) |
| 870 | (($ <compression> 'lzip level) | 886 | (($ <compression> 'lzip level) |
| 871 | (make-lzip-output-port (response-port response) | 887 | (make-lzip-output-port (response-port response) |
| 872 | #:level level)) | 888 | #:level level)) |
| @@ -891,8 +907,7 @@ blocking." | |||
| 891 | client)) | 907 | client)) |
| 892 | (port (begin | 908 | (port (begin |
| 893 | (force-output client) | 909 | (force-output client) |
| 894 | (setsockopt client SOL_SOCKET | 910 | (configure-socket client) |
| 895 | SO_SNDBUF (* 128 1024)) | ||
| 896 | (nar-response-port response compression)))) | 911 | (nar-response-port response compression)))) |
| 897 | ;; XXX: Given our ugly workaround for <http://bugs.gnu.org/21093> in | 912 | ;; XXX: Given our ugly workaround for <http://bugs.gnu.org/21093> in |
| 898 | ;; 'render-nar', BODY here is just the file name of the store item. | 913 | ;; 'render-nar', BODY here is just the file name of the store item. |
| @@ -922,7 +937,7 @@ blocking." | |||
| 922 | size) | 937 | size) |
| 923 | client)) | 938 | client)) |
| 924 | (output (response-port response))) | 939 | (output (response-port response))) |
| 925 | (setsockopt client SOL_SOCKET SO_SNDBUF (* 128 1024)) | 940 | (configure-socket client) |
| 926 | (if (file-port? output) | 941 | (if (file-port? output) |
| 927 | (sendfile output input size) | 942 | (sendfile output input size) |
| 928 | (dump-port input output)) | 943 | (dump-port input output)) |
| @@ -1067,7 +1082,8 @@ methods, return the applicable compression." | |||
| 1067 | (define (open-server-socket address) | 1082 | (define (open-server-socket address) |
| 1068 | "Return a TCP socket bound to ADDRESS, a socket address." | 1083 | "Return a TCP socket bound to ADDRESS, a socket address." |
| 1069 | (let ((sock (socket (sockaddr:fam address) SOCK_STREAM 0))) | 1084 | (let ((sock (socket (sockaddr:fam address) SOCK_STREAM 0))) |
| 1070 | (setsockopt sock SOL_SOCKET SO_REUSEADDR 1) | 1085 | (configure-socket sock #:options (cons (list SO_REUSEADDR 1) |
| 1086 | %default-socket-options)) | ||
| 1071 | (bind sock address) | 1087 | (bind sock address) |
| 1072 | sock)) | 1088 | sock)) |
| 1073 | 1089 | ||
