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

chore: add caching to azure pipelines #8866

Merged
merged 1 commit into from
Aug 26, 2019

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented Aug 22, 2019

Summary

Hopefully this'll speed up CI.

Test plan

Green CI with some nice cache output?

@@ -22,6 +22,12 @@ steps:
- script: node scripts/remove-postinstall
displayName: 'Remove postinstall script'

- task: CacheBeta@0
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

hope it's gonna work :D

@SimenB
Copy link
Member Author

SimenB commented Aug 22, 2019

Ergh
image

@willsmythe could you provide some info here? 🙏

@willsmythe
Copy link
Contributor

willsmythe commented Aug 22, 2019 via email

@SimenB
Copy link
Member Author

SimenB commented Aug 22, 2019

Cool, thanks! I've clicked the button. I guess a new run will also let me verify if the cache worked for the mac and windows runs, as they completed successfully 🙂

- task: CacheBeta@0
inputs:
key: yarn | $(Agent.OS) | yarn.lock
path: $(YARN_CACHE_FOLDER)
Copy link
Contributor

Choose a reason for hiding this comment

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

Btw, there is a caching feature coming in the next few weeks (tarring cache contents) that will make it easier/possible to cache node_modules. This generally results in better caching performance compared to caching the Yarn (or npm) global cache folder.

Definitely curious to see what improvements you get here. Keep in mind the first "save cache" operation within an org typically takes longer than future save operations (so don't be surprised if your first run takes longer than usual).

Copy link
Member Author

Choose a reason for hiding this comment

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

Awesome, that sounds great! That's what we cache on circus as well. I'll set up a reminder for myself to check back in a couple of weeks 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there an issue I could track for this work? I tried searching on https://github.com/microsoft/azure-pipelines-yaml (dunno if it's even the correct repo) without finding anything

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @SimenB - see microsoft/azure-pipelines-tasks#10925

Net-net: once your hosted agent's version (which is reported in the Initialize job step) shows as 2.157.0 or later, you can try caching the node_modules folder after setting the AZP_CACHING_TAR variable to true.

Copy link
Member Author

Choose a reason for hiding this comment

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

Awesome, thanks! Seems we're 2.155 for now, so I'll check back in a few days 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

@willsmythe I see we're getting the 2.160 agents now. Do you still recommend to change anything? The docs still state to cache the yarn cache folder: https://docs.microsoft.com/en-us/azure/devops/pipelines/caching/?view=azure-devops#nodejsyarn

Copy link
Contributor

Choose a reason for hiding this comment

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

@SimenB - yah we should try caching node_modules using the released version of the Cache task (V2). I'll test out a few options.

Copy link
Contributor

Choose a reason for hiding this comment

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

Here are a few tests. Note: I wouldn't say this is totally scientific because, as we have seen, there is some variability in terms of build time from one run to the next (even without any changes):

Option Install dependencies (Linux) Run tests (Windows) Total time
A. Yarn global 1m 7s 18m 22s (84%) 21m 57s
B. node_modules 1m 52s 18m 50s (80%) 23m 51s
C. node_modules and Yarn global 37s 18m 42s (86%) 21m 41s

Net-net: I don't think Jest will see huge performance improvements by switching to caching just node_modules versus Yarn's global cache directory. The added time to restore/save the extra bytes and thousands of files seems to offset any gains.

It is interesting that caching both (option C) resulted in better "install dependency" times, but just caching node_modules resulted in significantly worse times.

I experimented some with Yarn's offline cache, but didn't see any significant improvements.

The third column highlights where most of the overall time is spent (running tests). If you look at the Tests results for a run and filter to include Passing tests and order by Duration, you can see there are numerous tests (in all platforms) that take over 5s each. This obviously adds up over time.

image

Based on this, the best way to speed up Jest test runs is probably to split Jest test runs across more pipeline jobs,

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, ok. We'll leave it alone then. Thank you so much for diving into this @willsmythe!

@SimenB
Copy link
Member Author

SimenB commented Aug 22, 2019

Doesn't seem like the build wants to start for whatever reason. Maybe just a queue?

image

@willsmythe
Copy link
Contributor

Cool, thanks! I've clicked the button. I guess a new run will also let me verify if the cache worked for the mac and windows runs, as they completed successfully 🙂

@SimenB - do you recall which button you clicked? Was it in the GitHub Checks tab, or in Azure Pipelines? Asking because I see a new run (https://dev.azure.com/jestjs/jest/_build/results?buildId=3224&view=results), but it looks stalled. I've asked the engineering team here about this as well ...

@SimenB
Copy link
Member Author

SimenB commented Aug 22, 2019

Looks stuck, yeah. I clicked the Rebuild button here:

image

@SimenB
Copy link
Member Author

SimenB commented Aug 22, 2019

The build never triggered... Any idea what's going on?

@SimenB
Copy link
Member Author

SimenB commented Aug 26, 2019

I'll just rebase this, which should trigger a build.

@codecov-io
Copy link

Codecov Report

Merging #8866 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #8866   +/-   ##
=======================================
  Coverage   64.13%   64.13%           
=======================================
  Files         275      275           
  Lines       11627    11627           
  Branches     2845     2844    -1     
=======================================
  Hits         7457     7457           
  Misses       3544     3544           
  Partials      626      626

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6c5d96a...6b48a4d. Read the comment docs.

@SimenB SimenB merged commit 8c169d2 into jestjs:master Aug 26, 2019
@SimenB SimenB deleted the azure-pipeline-cache branch August 26, 2019 10:05
@SimenB
Copy link
Member Author

SimenB commented Aug 26, 2019

Ish 3 min install now on all OSes - hopefully we'll see an improvement

@SimenB
Copy link
Member Author

SimenB commented Aug 26, 2019

Yeah, it's about a minute faster, which is great:
image

Caching node_modules istead like @willsmythe mentions will be possible soon:tm: will probably be even faster, as the install step should be even shorter

@willsmythe
Copy link
Contributor

@SimenB - good to hear. The issue with the failed job (which only happens for some orgs on the very first job using caching) is being investigated. Looks to be a race condition. I haven't heard back from the team on the second issue (rebuild run fails to start).

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants