From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id YJloJWsM2l56JAAA0tVLHw (envelope-from ) for ; Fri, 05 Jun 2020 09:12:11 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id mHpTIWsM2l6KIQAA1q6Kng (envelope-from ) for ; Fri, 05 Jun 2020 09:12:11 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id C6E3D940308 for ; Fri, 5 Jun 2020 09:12:10 +0000 (UTC) Received: from localhost ([::1]:41370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh8OV-0002qr-SF for larch@yhetil.org; Fri, 05 Jun 2020 05:12:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37386) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh8OQ-0002qX-9W for guix-patches@gnu.org; Fri, 05 Jun 2020 05:12:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:36785) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh8OQ-0008HZ-15 for guix-patches@gnu.org; Fri, 05 Jun 2020 05:12:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jh8OP-0003eQ-SS for guix-patches@gnu.org; Fri, 05 Jun 2020 05:12:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41720] [PATCH] store: Use buffered I/O for all protocol writes Resent-From: Lars-Dominik Braun Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 05 Jun 2020 09:12:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 41720 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 41720@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.159134831914024 (code B ref -1); Fri, 05 Jun 2020 09:12:01 +0000 Received: (at submit) by debbugs.gnu.org; 5 Jun 2020 09:11:59 +0000 Received: from localhost ([127.0.0.1]:48331 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jh8ON-0003e8-EK for submit@debbugs.gnu.org; Fri, 05 Jun 2020 05:11:59 -0400 Received: from lists.gnu.org ([209.51.188.17]:43676) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jh8OL-0003dy-Ee for submit@debbugs.gnu.org; Fri, 05 Jun 2020 05:11:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37378) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh8OL-0002ps-A7 for guix-patches@gnu.org; Fri, 05 Jun 2020 05:11:57 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:46412) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh8OJ-0008G6-MD for guix-patches@gnu.org; Fri, 05 Jun 2020 05:11:57 -0400 Received: by mail-wr1-x441.google.com with SMTP id x6so8898436wrm.13 for ; Fri, 05 Jun 2020 02:11:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leibniz-psychology-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=L9IwGbkNF6IbfvD6DLQ1pqztR5umhq/kTVA+mpy/WP8=; b=pFwLY3sNKpryptdZqNT4g+SzudCRzjsGNcz7Ext8ptpmsLMh2q+FpGoRGSK1pe6KWX bp7Ej3+I8qfWg5G13qUGaht3piznVuAmPf3RrS7cNSOiIVWKchDGsPQ4NFqZAVwCsIHP 4xx9wLlJU4rU1x9hfvR8cBHbCZWVLhuibXb3S06jKACEQTstQ8xU26RgiGXfFoPp3c9H vQzzZTpCf9mUjWZmttlz1ZbYxUEkg+4LBP8gjB686J7ObSEg4Q6Kmd4j/pUTCZR+muu+ vN1fM+5KPdo4YupwVfxclgdeZAtiQI3DW7UoeBDKxLF+J2351qpF9yBJd3xdrkLqnyXJ JkrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=L9IwGbkNF6IbfvD6DLQ1pqztR5umhq/kTVA+mpy/WP8=; b=N7WIhjcvtuDsKoHhxnRg7b1y2A8bbo94WnXfxZQLHAmYsTS+SNlJ/KkugZDPQvoWUD L1u2NRtxH0zXow5KOERnEWmG8rnGZT5MKMBVFzteqD8nmS8JpWVqF8JbKQqWFHv1gtqP +BauwRpZ3LICUKKB74S4I6ypwtKxuRmAD3i06E3JSrsDOJpsWQv9nBQDSShPg98y1l+9 sX7EQk19F2orc2LaOPNQwNU5UyoVJNwJI8ghga3tT8CM4On9UHsrDzdlH8YTAXPjLbXi cbDHhCPSDHSyoX0hdoiDm0jwB3/7IUE8oIDsyWniL9+zvSPhW1xWTr9ESwfyL2PclwAt AYBA== X-Gm-Message-State: AOAM533A90xkqoFFUnaihPfi1QcgKwDPA9060JNE5cOoIQqW3KvtqJYU ohdA1wSBxa49rHzkoNYEAPMRCPtxji2L5/OLkspttQiiZqAan+bozwvZNULNp2LkVZTPXeVn5pH yFtnnMQFnwPL/z4z9fxPVtAFmBVNQ1kTbRiBOj3Dav9PKH7nPo5Pj5J3cdzpPtHGbBZF1OZMe/f 6+FgV05rU= X-Google-Smtp-Source: ABdhPJzFkbCOCS1XZIISvywNN9en3h0k34SE5VfrkUa115Wsa9sY702StKvOHNFvfIcQEOWB5U5+Jg== X-Received: by 2002:a5d:4f81:: with SMTP id d1mr9044251wru.95.1591348313095; Fri, 05 Jun 2020 02:11:53 -0700 (PDT) Received: from localhost (dynamic-2a01-0c22-c874-1100-1842-9ea3-2bc6-059b.c22.pool.telefonica.de. [2a01:c22:c874:1100:1842:9ea3:2bc6:59b]) by smtp.gmail.com with ESMTPSA id g187sm10915271wma.17.2020.06.05.02.11.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 02:11:52 -0700 (PDT) Date: Fri, 5 Jun 2020 11:11:51 +0200 From: Lars-Dominik Braun Message-ID: <20200605091151.GB3225@zpidnp36> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="vOmOzSkFvhd7u8Ms" Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Received-SPF: none client-ip=2a00:1450:4864:20::441; envelope-from=ldb@leibniz-psychology.org; helo=mail-wr1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -3.3 (---) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=fail (rsa verify failed) header.d=leibniz-psychology-org.20150623.gappssmtp.com header.s=20150623 header.b=pFwLY3sN; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Spam-Score: -1.61 X-TUID: CrfCO//5hOv/ --vOmOzSkFvhd7u8Ms Content-Type: multipart/mixed; boundary="XOIedfhf+7KOe/yw" Content-Disposition: inline --XOIedfhf+7KOe/yw Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, I did some digging to investigate why SSH-based guix operations are current= ly so slow. One of the reasons seems to be that some operations write single w= ords to the socket and due to NOWAIT these result in a lot of small packets. The attached patch modifies store.scm to buffer all writes, so that won=E2= =80=99t happen any more. I=E2=80=99m seeing about ~40% speedup (6.194s vs 10.075s for the = best out of five runs) for `GUIX_DAEMON_SOCKET=3Dssh://localhost guix environment guix = -- true`, but it also seems to have a negative impact on UNIX domain socket communication by ~10% (1.561s vs 1.385s). For the notorious r-learnr package it=E2=80=99s still ~20% better (ssh, 16.620/21.418) and only ~3% worse (uni= x, 11.489/11.199). Keep in mind localhost has a much larger MTU and much lower latency than usual networks though. It might benefit from having an even bi= gger write buffer (64k vs. currently 8k). Cheers, Lars --XOIedfhf+7KOe/yw Content-Type: text/x-diff; charset=iso-8859-1 Content-Disposition: attachment; filename="0001-store-Use-buffered-I-O-for-all-protocol-writes.patch" Content-Transfer-Encoding: quoted-printable =46rom eb38dc246e5dd33f8a48a99aded8b8dc0c378376 Mon Sep 17 00:00:00 2001 =46rom: Lars-Dominik Braun Date: Fri, 5 Jun 2020 10:38:32 +0200 Subject: [PATCH] store: Use buffered I/O for all protocol writes * guix/store.scm (run-gc) Use buffered output port. (export-path) Same. (add-file-tree-to-store) Same. (set-build-options): Same. Add explicit flush. --- guix/store.scm | 70 ++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/guix/store.scm b/guix/store.scm index 014d08aaec..9b3879b4a7 100644 --- a/guix/store.scm +++ b/guix/store.scm @@ -3,6 +3,7 @@ ;;; Copyright =A9 2018 Jan Nieuwenhuizen ;;; Copyright =A9 2019, 2020 Mathieu Othacehe ;;; Copyright =A9 2020 Florian Pelz +;;; Copyright =A9 2020 Lars-Dominik Braun ;;; ;;; This file is part of GNU Guix. ;;; @@ -821,8 +822,8 @@ encoding conversion errors." (locale (false-if-exception (setlocale LC_ALL)= ))) ;; Must be called after `open-connection'. =20 - (define socket - (store-connection-socket server)) + (define buffered + (store-connection-output-port server)) =20 (unless (unspecified? use-build-hook?) (warn-about-deprecation #:use-build-hook? #f @@ -831,9 +832,9 @@ encoding conversion errors." (let-syntax ((send (syntax-rules () ((_ (type option) ...) (begin - (write-arg type option socket) + (write-arg type option buffered) ...))))) - (write-int (operation-id set-options) socket) + (write-int (operation-id set-options) buffered) (send (boolean keep-failed?) (boolean keep-going?) (boolean fallback?) (integer verbosity)) (when (< (store-connection-minor-version server) #x61) @@ -896,6 +897,7 @@ encoding conversion errors." `(("locale" . ,locale)) '())))) (send (string-pairs pairs)))) + (write-buffered-output server) (let loop ((done? (process-stderr server))) (or done? (process-stderr server))))) =20 @@ -1108,13 +1110,14 @@ path." ;; We don't use the 'operation' macro so we can pass SELECT? to ;; 'write-file'. (record-operation 'add-to-store) - (let ((port (store-connection-socket server))) - (write-int (operation-id add-to-store) port) - (write-string basename port) - (write-int 1 port) ;obsolete, must be #t - (write-int (if recursive? 1 0) port) - (write-string hash-algo port) - (write-file file-name port #:select? select?) + (let ((port (store-connection-socket server)) + (buffered (store-connection-output-port server))) + (write-int (operation-id add-to-store) buffered) + (write-string basename buffered) + (write-int 1 buffered) ;obsolete, must be #t + (write-int (if recursive? 1 0) buffered) + (write-string hash-algo buffered) + (write-file file-name buffered #:select? select?) (write-buffered-output server) (let loop ((done? (process-stderr server))) (or done? (loop (process-stderr server)))) @@ -1220,13 +1223,14 @@ an arbitrary directory layout in the store without = creating a derivation." ;; We don't use the 'operation' macro so we can use 'write-file-tr= ee' ;; instead of 'write-file'. (record-operation 'add-to-store/tree) - (let ((port (store-connection-socket server))) - (write-int (operation-id add-to-store) port) - (write-string basename port) - (write-int 1 port) ;obsolete, must be #t - (write-int (if recursive? 1 0) port) - (write-string hash-algo port) - (write-file-tree basename port + (let ((port (store-connection-socket server)) + (buffered (store-connection-output-port server))) + (write-int (operation-id add-to-store) buffered) + (write-string basename buffered) + (write-int 1 buffered) ;obsolete, must be #t + (write-int (if recursive? 1 0) buffered) + (write-string hash-algo buffered) + (write-file-tree basename buffered #:file-type+size file-type+size #:file-port file-port #:symlink-target symlink-target @@ -1644,17 +1648,19 @@ the list of store paths to delete. IGNORE-LIVENESS= ? should always be #f. MIN-FREED is the minimum amount of disk space to be freed, in bytes, before the GC can stop. Return the list of store paths delete, and the number of bytes freed." - (let ((s (store-connection-socket server))) - (write-int (operation-id collect-garbage) s) - (write-int action s) - (write-store-path-list to-delete s) - (write-arg boolean #f s) ; ignore-liveness? - (write-long-long min-freed s) - (write-int 0 s) ; obsolete + (let ((s (store-connection-socket server)) + (buffered (store-connection-output-port server))) + (write-int (operation-id collect-garbage) buffered) + (write-int action buffered) + (write-store-path-list to-delete buffered) + (write-arg boolean #f buffered) ; ignore-liveness? + (write-long-long min-freed buffered) + (write-int 0 buffered) ; obsolete (when (>=3D (store-connection-minor-version server) 5) ;; Obsolete `use-atime' and `max-atime' parameters. - (write-int 0 s) - (write-int 0 s)) + (write-int 0 buffered) + (write-int 0 buffered)) + (write-buffered-output server) =20 ;; Loop until the server is done sending error output. (let loop ((done? (process-stderr server))) @@ -1711,10 +1717,12 @@ is raised if the set of paths read from PORT is not= signed (as per =20 (define* (export-path server path port #:key (sign? #t)) "Export PATH to PORT. When SIGN? is true, sign it." - (let ((s (store-connection-socket server))) - (write-int (operation-id export-path) s) - (write-store-path path s) - (write-arg boolean sign? s) + (let ((s (store-connection-socket server)) + (buffered (store-connection-output-port server))) + (write-int (operation-id export-path) buffered) + (write-store-path path buffered) + (write-arg boolean sign? buffered) + (write-buffered-output server) (let loop ((done? (process-stderr server port))) (or done? (loop (process-stderr server port)))) (=3D 1 (read-int s)))) --=20 2.20.1 --XOIedfhf+7KOe/yw-- --vOmOzSkFvhd7u8Ms Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEEyk+M9DfXR4/aBV/UQhN3ARo3hEYFAl7aDFMACgkQQhN3ARo3 hEaxtgv/dpe1nWch2+Hfx3WBMZha9WyyFjW8TeasbC5cdy5bccYwasr5Q3Zd+Xbr FYBubNTUkMZz4p5M4qIC1QRloyXf9GlkSYKY7VTYGEXmlIa6mPPzwpkcq0xcJTl3 vypg12EhiBJBXA0KuGpkWgn8Cgxb7y0K1fHeWHa2o+oPXXdVqgJt36oK+bxxkkTH pmv0D4PhDWnxMv0wvYdz6ls5TYiIqUGpSufMIh9ynEiXBkGz/0J4bEGVV5aSKBrF LEB01Pr7TSuR9UDg+OqEz7Q7MMVEN63BaQkxJOi2rBdVLDX/C713LHjgzSahXY37 OzOQZUFX8aCPF4dJSutyUhOUKsdOyR7K3qGxlvuRiCmzHotSym1kWIDuo/9f1e1H h1YOutEHUIiOyiPmo941h5GlGV0qZuFCjKEu4Y7SXT0UYAR1vieL4RIzc6E0IY+m xrLixnn1pSOn4ebeuB+QDxha/VmvyPXo2nUBwOKuXhn9dGld5x0nYWsjrC7Pj91i DSdSf1Xm =THIV -----END PGP SIGNATURE----- --vOmOzSkFvhd7u8Ms--