Code Monkey home page Code Monkey logo

Comments (15)

glambert avatar glambert commented on June 14, 2024 1

Trying it out right now, thanks a lot for the fast reply πŸ‘

from cache.

joshmgross avatar joshmgross commented on June 14, 2024 1

You can definitely use a node_modules in your cache instead of caching the yarn cache directly, that's how we handle caching with npm (npm has a cache but it's not meant to be populated by the user).

I'd recommend trying it out and seeing which is faster

from cache.

glambert avatar glambert commented on June 14, 2024 1

@teohhanhui to be confirmed, we only use yarn so I can't tell. I'd say this is the subject for another issue.

In any case, yarn caching works to an extent here, so I'll close this issue. Thanks again for your help @joshmgross πŸ‘

from cache.

glambert avatar glambert commented on June 14, 2024

As a follow-up, if I use path: node_modules it does save the cache successfully:

Cache yarn node_modules1s
Cache not found for input keys: ["Linux-yarn-db9ae0b40b59cc89d84b533d906606822c72106dfc77455cf7eee198d6e55858","Linux-yarn-"].
Run actions/cache@v1
  with:
    path: node_modules
    key: Linux-yarn-db9ae0b40b59cc89d84b533d906606822c72106dfc77455cf7eee198d6e55858
    restore-keys: Linux-yarn-
  
Cache not found for input keys: ["Linux-yarn-db9ae0b40b59cc89d84b533d906606822c72106dfc77455cf7eee198d6e55858","Linux-yarn-"].

...

Post Cache yarn node_modules27s
Cache saved successfully
Post job cleanup.
/bin/tar -cz -f /home/runner/work/_temp/86ca5e8a-8003-4159-b3a0-36827075ec88/cache.tgz -C /home/runner/work/web-tools/web-tools/node_modules .
Cache saved successfully

And when I re-run the task, I get this, but yarn does not actually re-run from cache as it take same amount of time as with a clean yarn install:

Run actions/cache@v1
/bin/tar -xz -f /home/runner/work/_temp/ce74f1ec-ba00-4e1f-9508-f80715195305/cache.tgz -C /home/runner/work/web-tools/web-tools/node_modules
::set-output name=cache-hit,::true
Cache restored from key: Linux-yarn-db9ae0b40b59cc89d84b533d906606822c72106dfc77455cf7eee198d6e55858

Could that be related?

from cache.

glambert avatar glambert commented on June 14, 2024

With the recent increase to 400MB now it does save the cache, but yarn still does not seem to pick up the cache from ~/.cache/yarn and still does a clean install. If I do yarn cache dir it outputs /home/runner/.cache/yarn/v6.

from cache.

joshmgross avatar joshmgross commented on June 14, 2024

It's possible there's additional content in ~/.cache/yarn that's leading to the file size discrepancy between local and the runner. It could be something populated during actions/setup-node.

~/.cache/yarn may not work for all scenarios, and a better example could use yarn cache dir to determine the path and accessing that via an output.

Example:

- name: Get Yarn Cache Directory
  id: yarn-cache
  run: |
    echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
  with:
    path: ${{ steps.yarn-cache.outputs.dir }}
          key: ${{ runner.OS }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-

from cache.

glambert avatar glambert commented on June 14, 2024

So the cache folder is indeed different:

Run echo "::set-output name=dir::$(yarn cache dir)"
::set-output name=dir::/home/runner/.cache/yarn/v6

Then:

Run actions/cache@v1
/bin/tar -xz -f /home/runner/work/_temp/3b300616-8bbe-4e56-b10d-dcbc31bbca18/cache.tgz -C /home/runner/.cache/yarn/v6
::set-output name=cache-hit,::true
Cache restored from key: Linux-yarn-db9ae0b40b59cc89d84b533d906606822c72106dfc77455cf7eee198d6e55858

But install still takes 2.55min to run. Full thing:

- name: Use Node.js 10.16.0
  uses: actions/setup-node@v1
  with:
    node-version: 10.16.0
- name: Get Yarn Cache Directory
  id: yarn-cache
  run: |
    echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
  with:
    path: ${{ steps.yarn-cache.outputs.dir }}
    key: ${{ runner.OS }}-yarn-${{ hashFiles('**/yarn.lock') }}
    restore-keys: |
      ${{ runner.os }}-yarn-
- name: Install
  run: yarn install --frozen-lockfile

from cache.

joshmgross avatar joshmgross commented on June 14, 2024

But install still takes 2.55min to run

What install times are you seeing without the cache?

You could try inserting a view yarn cache list calls to verify what's in the cache before and after. See https://yarnpkg.com/en/docs/cli/cache#toc-yarn-cache-list-pattern

from cache.

glambert avatar glambert commented on June 14, 2024

What install times are you seeing without the cache?

Same time. Let me try yarn cache list.

from cache.

glambert avatar glambert commented on June 14, 2024

Hmmm interesting:

Run yarn cache list && yarn install --frozen-lockfile
yarn cache v1.19.1
error An unexpected error occurred: "ENOENT: no such file or directory, scandir '/home/runner/.cache/yarn/v6/@apollo/node_modules'".

from cache.

glambert avatar glambert commented on June 14, 2024

Ok, so I renamed the cache key and now yarn cache list does show a bunch of packages. I did get 1min shaved off the install step too now (so install now takes around 2min instead of 3min), so I guess caching semi-works? What do you think? Should it be faster?

from cache.

joshmgross avatar joshmgross commented on June 14, 2024

1 minute sounds reasonable, as yarn install might be doing other work besides just fetching packages.

Unfortunately, it all depends on specific ecosystems and use-cases. Some scenarios will have much larger savings when caching, while others won't see much benefit.

For comparison, how long does install take on your local machine?
Ignoring all differences in CPU speed and resources, that would be the ideal install time as it's a fully populated cache (assuming this isn't a fresh install).

from cache.

glambert avatar glambert commented on June 14, 2024

So to replicate exactly the same scenario as with GitHub Actions, I’d need to remove my local node_modules and run yarn install β€”frozen-lockfile and that should be very similar, correct?

In fact, would it be possible to pre-populate node_modules with the cache before doing the install step? With this it would be pretty much instantaneous. Or is there caveats with this approach?

By the way, we use workspaces so that might come into play as well.


Update:

  • Local yarn --frozen-lockfile after deleting node_modules: 157.49s
  • GitHub Actions: 127.39s

Note that I'm currently tethering from my phone so network latency might come into play. Pretty sure in the end it would be pretty similar.


So my last question is: can we somehow keep or restore a cached node_modules folder instead of using the global cache? I know CircleCI somehow does this on the install step, could it be feasible with GitHub Actions?

from cache.

glambert avatar glambert commented on June 14, 2024

Using node_modules yields the same result as not using cache, which is weird. Probably missing something for yarn cache to happen correctly. Is it due to Docker maybe?

I even tried caching both node_modules and ~/.cache/yarn but no improvements either.

For now it seems only using the ~/.cache/yarn folder is the best approach. I was comparing with CircleCI but I think in their case they use Docker Layer Caching so node_modules are cached by default. Even in their docs they only mention caching ~/.cache/yarn: https://circleci.com/docs/2.0/caching/#yarn-node.

from cache.

teohhanhui avatar teohhanhui commented on June 14, 2024

Caching node_modules is just weird (and would likely cause issues)... There's npm ci: https://docs.npmjs.com/cli/ci

from cache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.