unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Christopher Baines <mail@cbaines.net>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: 69291@debbugs.gnu.org
Subject: [bug#69291] [PATCH 4/5] scripts: substitute: Untangle selecting fast vs small compressions.
Date: Wed, 03 Apr 2024 18:28:15 +0100	[thread overview]
Message-ID: <87o7aqjqz4.fsf@cbaines.net> (raw)
In-Reply-To: <87sf1jf8os.fsf@gnu.org> ("Ludovic Courtès"'s message of "Fri, 23 Feb 2024 17:26:43 +0100")

[-- Attachment #1: Type: text/plain, Size: 4219 bytes --]

Ludovic Courtès <ludo@gnu.org> writes:

> Christopher Baines <mail@cbaines.net> skribis:
>
>> Pulling the logic up to the script makes this code more portable and not
>> reliant on setting a global variable.
>>
>> * guix/scripts/substitute.scm (%prefer-fast-decompression?): Rename to…
>> (%default-prefer-fast-decompression?): this.
>> (display-narinfo-data): Update accordingly.
>> (download-nar): Add prefer-fast-decompression? as a keyword argument, remove
>> code to set! it and return the cpu-usage recorded.
>> (process-substitution, process-substitution/fallback): Accept and pass through
>> prefer-fast-decompression? to download-nar.
>> (guix-substitute): Move the prefer fast decompression switching logic here.
>>
>> Change-Id: I4e80b457b55bcda8c0ff4ee224dd94a55e1b24fb
>
> [...]
>
>> -(define %prefer-fast-decompression?
>> -  ;; Whether to prefer fast decompression over good compression ratios.  This
>> -  ;; serves in particular to choose between lzip (high compression ratio but
>> -  ;; low decompression throughput) and zstd (lower compression ratio but high
>> -  ;; decompression throughput).
>> -  #f)
>> +(define %default-prefer-fast-decompression? #f)
>
> I would either remove this variable or add a comment describing it (we
> should do that for all top-level variables).

I've added a comment now, and I'll sent an updated patch.

>> @@ -604,7 +585,9 @@ (define* (download-nar narinfo destination
>>              (format status-port "hash-mismatch ~a ~a ~a~%"
>>                      (hash-algorithm-name algorithm)
>>                      (bytevector->nix-base32-string expected)
>> -                    (bytevector->nix-base32-string actual)))))))
>> +                    (bytevector->nix-base32-string actual))))
>> +
>> +      cpu-usage)))
>
> [...]
>
>> +               (let ((cpu-usage
>> +                      (process-substitution reply-port store-path destination
>> +                                            #:cache-urls (substitute-urls)
>> +                                            #:acl (current-acl)
>> +                                            #:deduplicate? deduplicate?
>> +                                            #:print-build-trace?
>> +                                            print-build-trace?
>> +                                            #:prefer-fast-decompression?
>> +                                            prefer-fast-decompression?)))
>> +
>> +                 ;; Create a hysteresis: depending on CPU usage, favor
>> +                 ;; compression methods with faster decompression (like ztsd)
>> +                 ;; or methods with better compression ratios (like lzip).
>> +                 ;; This stems from the observation that substitution can be
>> +                 ;; CPU-bound when high-speed networks are used:
>> +                 ;; <https://lists.gnu.org/archive/html/guix-devel/2020-12/msg00177.html>.
>> +                 ;; To simulate "slow" networking or changing conditions, run:
>> +                 ;; sudo tc qdisc add dev eno1 root tbf rate 512kbit latency
>> +                 ;; 50ms burst 1540 and then cancel with: sudo tc qdisc del
>> +                 ;; dev eno1 root
>> +                 (loop (cond
>> +                        ;; Whether to prefer fast decompression over good
>> +                        ;; compression ratios.  This serves in particular to
>> +                        ;; choose between lzip (high compression ratio but low
>> +                        ;; decompression throughput) and zstd (lower
>> +                        ;; compression ratio but high decompression
>> +                        ;; throughput).
>> +                        ((> cpu-usage .8) #t)
>> +                        ((< cpu-usage .2) #f)
>> +                        (else prefer-fast-decompression?)))))))))
>
>
> Instead of having ‘download-nar’ return its CPU usage, which is
> surprising, maybe should wrap the ‘process-substitution’ call in
> ‘guix-substitute’ in ‘with-cpu-usage-monitoring’ and keep all the logic
> in ‘guix-substitute’?

Yeah, that makes sense. I'll send an updated patch shortly.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 987 bytes --]

  reply	other threads:[~2024-04-03 17:29 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-20 19:05 [bug#69291] [PATCH 0/5] Start making substitute code less coupled Christopher Baines
2024-02-20 19:42 ` [bug#69291] [PATCH 1/5] scripts: substitute: Remove side effect warning from network-error? Christopher Baines
2024-02-20 19:42   ` [bug#69291] [PATCH 2/5] scripts: substitute: Allow not using with-timeout in download-nar Christopher Baines
2024-02-23 16:19     ` Ludovic Courtès
2024-04-03 17:26       ` Christopher Baines
2024-02-20 19:42   ` [bug#69291] [PATCH 3/5] scripts: substitute: Replace some leave calls with raise Christopher Baines
2024-02-23 16:20     ` Ludovic Courtès
2024-02-20 19:42   ` [bug#69291] [PATCH 4/5] scripts: substitute: Untangle selecting fast vs small compressions Christopher Baines
2024-02-23 16:26     ` Ludovic Courtès
2024-04-03 17:28       ` Christopher Baines [this message]
2024-02-20 19:42   ` [bug#69291] [PATCH 5/5] scripts: substitute: Extract script specific output from download-nar Christopher Baines
2024-02-23 16:27     ` Ludovic Courtès
2024-04-03 17:30       ` Christopher Baines
2024-04-21 11:24         ` bug#69291: " Christopher Baines
2024-02-23 16:16   ` [bug#69291] [PATCH 1/5] scripts: substitute: Remove side effect warning from network-error? Ludovic Courtès
2024-04-04 14:06 ` [bug#69291] [PATCH v2 1/2] scripts: substitute: Untangle selecting fast vs small compressions Christopher Baines
2024-04-04 14:06   ` [bug#69291] [PATCH v2 2/2] scripts: substitute: Extract script specific output from download-nar Christopher Baines

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=87o7aqjqz4.fsf@cbaines.net \
    --to=mail@cbaines.net \
    --cc=69291@debbugs.gnu.org \
    --cc=ludo@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).