Skip to content

BinaryCacheStore: Improve upload parallelism#15957

Open
edolstra wants to merge 2 commits into
masterfrom
binary-cache-store-add-multiple
Open

BinaryCacheStore: Improve upload parallelism#15957
edolstra wants to merge 2 commits into
masterfrom
binary-cache-store-add-multiple

Conversation

@edolstra
Copy link
Copy Markdown
Member

@edolstra edolstra commented Jun 2, 2026

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:

# 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.

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.

edolstra and others added 2 commits June 2, 2026 11:01
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.
@edolstra edolstra requested a review from Ericson2314 as a code owner June 2, 2026 09:13
@github-actions github-actions Bot added the store Issues and pull requests concerning the Nix store label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

store Issues and pull requests concerning the Nix store

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant