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

JIT cache implementation #15

Closed
wants to merge 3 commits into from
Closed

JIT cache implementation #15

wants to merge 3 commits into from

Conversation

nrdxp
Copy link
Contributor

@nrdxp nrdxp commented Dec 12, 2022

Partially fixes #13.

The initial implementation allows a user to optionally pull the target derivation from the configured Nix cache. It's availability can be determined by using the cached output from the discover action.

This includes a refactoring of secrets into their own action so it can be used to setup secrets for both discovery and for the runners. All secret related inputs to the run action have been moved into this new action.

For projects that produce a large /nix/store in the discovery phase, this should drastically increase task startup time. In order to improve total action runtime further, we would need a more granular needs that can skip waiting on the post step for the discover action.

We should probably request this upstream, but I am not sure where would be appropriate. actions/toolkit perhaps?

This is so discovery can properly setup secrets for uploading results
to a Nix cache.
Pulling a single derivation and its deps from a Nix cache is a lot
faster than pulling the entire /nix/store produced by the discovery
phase, so allow us to skip the GitHub cache restoration if they are
available.
@nrdxp
Copy link
Contributor Author

nrdxp commented Dec 13, 2022

So after getting this to "work" and testing it out, it is going to be even more expensive during the upload phase because querying the cache for existing paths is massively inefficient en masse currently: NixOS/nix#7221 (comment)

We could set a massive narinfo-cache-positive-ttl so that the query cache doesn't ever expire, but I'm not sure if that might cause other issues 🤔

Plus, even after waiting a full hour in the CI runner, the task cache never even finished querying paths, so I'm not sure if I'll ever be able to poppulate the query cache in the first place.

Update
Some basic math that I'm sure isn't strictly accurate but perhaps a rough estimate. I uploaded all the derivations from my local machine, there were about 30,000 individual uploads, but the part I want to focus on is the query time. After I ran the upload I did another cycle with all the ttl's set to 0 to see how long just a straight query would take. On my 12 core cpu it took 8m23s.

The default GH Linux runner has 2 cores, so some rough math would have us waiting aproximately 51 minutes just to query that the derivations already exist in the cache 🤦

@nrdxp nrdxp marked this pull request as draft December 13, 2022 20:23
@nrdxp
Copy link
Contributor Author

nrdxp commented Dec 13, 2022

Moving to draft unless/until we find a better solution to this. Our hopes for efficient persistent state in the case of heavy evaluations will have to rest on #14 for now.

This did give me an idea for a new project though: maybe at some point in the future we could write some kind of frontend that can index a Nix cache and provide cheaper query API. In order for it to be really useful though it would also need to know how to write to the cache, so you'd probably have to teach the nix cli how to talk to this frontend if it is available, rather than manually querying each path individually.

In any case, just a thought I wanted to get down in case we ever have time to work it out further.

@nrdxp nrdxp force-pushed the main branch 2 times, most recently from 115242f to 12fbb7e Compare December 17, 2022 02:54
@blaggacao
Copy link
Collaborator

blaggacao commented Dec 19, 2022

For context of future readers.

This has progressed via #14 into:

ssh "$DISCOVERY_SSH" -- \ 
  'nix-store --export \ 
    $(nix-store --query --requisites \ 
      ${{ fromJSON(inputs.json).targetDrv }} \
      ${{ fromJSON(inputs.json).actionDrv }} \
    ) \ 
  | zstd' \ 
| unzstd \ 
| nix-store --import &>/dev/null

@nrdxp nrdxp force-pushed the main branch 2 times, most recently from 0ac0efd to e3ef02b Compare January 5, 2023 16:47
@nrdxp nrdxp closed this Jan 10, 2023
@blaggacao blaggacao deleted the eval-cache branch March 24, 2023 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JIT cached artifacts
2 participants