BinaryCacheStore: Improve upload parallelism#15957
Open
edolstra wants to merge 2 commits into
Open
Conversation
Previously NARs were uploaded along with the narinfos in a topological ordering, i.e. we didn't upload a NAR until all the NARs/narinfos of its references were uploaded. However, for preserving the closure invariant, it's only needed to maintain an ordering between the narinfo uploads, since the existence of a narinfo determines whether a store path is considered "valid" in the binary cache. So now we drop the ordering requirement between NARs; we only require a NAR to be uploaded before its narinfo. Also, NARs are now uploaded in order of descending NAR size. This typically reduces the makespan since if there is a giant NAR that takes forever to upload/compress, it's best to start as soon as possible. As an example, this speeds up a copy between two binary caches: nix copy --from file:///tmp/binary-cache --to file:///tmp/binary-cache-2?compression=xz --no-check-sigs /nix/store/8xyk1qxxjfb8cm62g61yc59phwha92w7-kdenlive-25.08.3 from 117.7s to 47.2s. However, whether you get a speedup highly depends on the shape of the graph; e.g. NixOS system configurations are often dominated by a few giant store paths (e.g. `linux-firmware` - 750 MiB) which may take longer than all the other paths together in parallel. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
In 602a1f8 we decided it's now the responsibility of the caller to drain the source (using `EnsureRead`) if that's important. Usually it isn't, so we don't want to read a NAR we don't need.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Previously NARs were uploaded along with the narinfos in a topological ordering, i.e. we didn't upload a NAR until all the NARs/narinfos of its references were uploaded. However, for preserving the closure invariant, it's only needed to maintain an ordering between the narinfo uploads, since the existence of a narinfo determines whether a store path is considered "valid" in the binary cache.
So now we drop the ordering requirement between NARs; we only require a NAR to be uploaded before its narinfo.
Also, NARs are now uploaded in order of descending NAR size. This typically reduces the makespan since if there is a giant NAR that takes forever to upload/compress, it's best to start as soon as possible.
As an example, this speeds up a copy between two binary caches:
from 117.7s to 47.2s.
However, whether you get a speedup highly depends on the shape of the graph; e.g. NixOS system configurations are often dominated by a few giant store paths (e.g.
linux-firmware- 750 MiB) which may take longer than all the other paths together in parallel.Also removed the calls to
drain()that should be unncessary now (see 602a1f8).Taken from DeterminateSystems#477.
Context
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.