Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--eval-store and faster closure copying #5048

Merged
merged 15 commits into from
Jul 27, 2021
Merged

Conversation

edolstra
Copy link
Member

@edolstra edolstra commented Jul 26, 2021

When the Nix daemon is running remotely and is accessed via a high-latency connection, an operation like nix build nixpkgs#hello can be very slow because the client first needs to send a lot of .drv files one-by-one to the remote, each requiring a round trip. To make this faster, this PR does the following:

  • It adds an option --eval-store that allows the evaluation to be done in a local Nix store. This is also useful for store that can't build, like binary caches. For instance, you can now do:

    # nix path-info --json --store https://cache.nixos.org --eval-store auto nixpkgs#hello
    
  • It adds a new worker protocol interface to add multiple store paths in the same call. On a link with a 50 ms delay, this speeds up the copying of the hello .drv closure from 57.8s to 0.7s. Note that this disables parallel copying (the use of processGraph() with a thread pool in copyPaths() is commented out).

Fixes #5026.
Partially fixes #5025.

edolstra added 15 commits July 22, 2021 09:59
In particular, this now works:

  $ nix path-info --eval-store auto --store https://cache.nixos.org nixpkgs#hello

Previously this would fail as it would try to upload the hello .drv to
cache.nixos.org. Now the .drv is instantiated in the local store, and
then we check for the existence of the outputs in cache.nixos.org.
With this, we don't have to copy the entire .drv closure to the
destination store ahead of time (or at all). Instead, buildPaths()
reads .drv files from the eval store and copies inputSrcs to the
destination store if it needs to build a derivation.

Issue NixOS#5025.
This adds a new store operation 'addMultipleToStore' that reads a
number of NARs and ValidPathInfos from a Source, allowing any number
of store paths to be copied in a single call. This is much faster on
high-latency links when copying a lot of small files, like .drv
closures.

For example, on a connection with an 50 ms delay:

Before:

  $ nix copy --to 'unix:///tmp/proxy-socket?root=/tmp/dest-chroot' \
    /nix/store/90jjw94xiyg5drj70whm9yll6xjj0ca9-hello-2.10.drv \
    --derivation --no-check-sigs
  real    0m57.868s
  user    0m0.103s
  sys     0m0.056s

After:

  real    0m0.690s
  user    0m0.017s
  sys     0m0.011s
@edolstra edolstra merged commit c000cec into NixOS:master Jul 27, 2021
@edolstra edolstra deleted the flox-eval-store branch July 27, 2021 10:20
@Mic92
Copy link
Member

Mic92 commented Jul 28, 2021

How can I enable --eval-store auto globally?

@edolstra
Copy link
Member Author

You can't since it's not a config option and I'm not sure if it makes sense to turn it into one, since it could have unexpected interactions with scripts that use --store.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/tweag-nix-dev-update-16/14379/1

Comment on lines +109 to +112
static ValidPathInfo read(Source & source, const Store & store, unsigned int format);
static ValidPathInfo read(Source & source, const Store & store, unsigned int format, StorePath && path);

void write(Sink & sink, const Store & store, unsigned int format, bool includePath = true) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be part of the core data type, but instead defined like and with the other serializers in src/libstore/worker-protocol.hh.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/tweag-nix-dev-update-32/19865/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants