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

ci: persist Rust caches for Pip package build #4480

Merged
merged 3 commits into from
Dec 15, 2020

Conversation

wchargin
Copy link
Contributor

@wchargin wchargin commented Dec 15, 2020

Summary:
The build-data-server-pip job runs on two platforms on every push, and
each run takes about 5 minutes. The vast majority of this time (85%) is
spent building all dependencies from scratch. Since macOS minutes are
priced at 10× the rate of Linux minutes
and this is our only
macOS job, we may as well spend a modicum of effort to improve this.

The docs at https://github.com/actions/cache say that a repository can
have up to 5 GB of caches. The cache for our other Rust job is ~200 MB,
and we don’t have any other caches, so adding two more of those caches
seems okay. The caches are also invalidated infrequently: only when we
update Rust dependencies or update the workflow file itself.

Adding a cache should speed up these builds. We already do this for the
Rust lint job, and it works well. This is a separate cache because the
job builds in release mode rather than debug mode.

Rust builds generally have good hermeticity properties, so this should
be fairly safe. If we want to be extra safe, we could turn this off for
builds that will be published in an actual stable release.

Test Plan:
Note that the second run of the checks for this PR spends less time in
the “Build” and “Test” phases. It appears to still spend about a minute
total building, even though it hits cache. I’m not sure why—this is not
the case for normal, local, incremental builds—but this is still an
improvement of about 65%, so I’m okay with it for now.

wchargin-branch: ci-cache-rust-pip

Summary:
The `build-data-server-pip` job runs on two platforms on every push, and
each run takes about 5 minutes. The vast majority of this time (85%) is
spent building all dependencies from scratch. Since [macOS minutes are
priced at 10× the rate of Linux minutes][pricing] and this is our only
macOS job, we may as well spend a modicum of effort to improve this.

[pricing]: https://docs.github.com/en/free-pro-team@latest/github/setting-up-and-managing-billing-and-payments-on-github/about-billing-for-github-actions#about-billing-for-github-actions

The docs at <https://github.com/actions/cache> say that a repository can
have up to 5 GB of caches. The cache for our other Rust job is ~200 MB,
and we don’t have any other caches, so adding two more of those caches
seems okay. The caches are also invalidated infrequently: only when we
update Rust dependencies or update the workflow file itself.

Adding a cache should speed up these builds. We already do this for the
Rust lint job, and it works well. This is a separate cache because the
job builds in release mode rather than debug mode.

Rust builds generally have good hermeticity properties, so this should
be fairly safe. If we want to be extra safe, we could turn this off for
builds that will be published in an actual stable release.

Test Plan:
Check that the second run of the checks for this PR spends a negligible
amount of time in the “Build” and “Test” phases.

wchargin-branch: ci-cache-rust-pip
wchargin-source: 631d316bed4c17387901b166c6d8d28a6f8c8b7f
@wchargin wchargin added theme:performance Performance, scalability, large data sizes, slowness, etc. dependencies Pull requests that update a dependency file core:rustboard //tensorboard/data/server/... labels Dec 15, 2020
@wchargin wchargin requested a review from nfelt December 15, 2020 18:19
@google-cla google-cla bot added the cla: yes label Dec 15, 2020
@wchargin wchargin removed the request for review from nfelt December 15, 2020 18:25
@wchargin
Copy link
Contributor Author

(Unassigning just because I haven’t finished the test plan yet.)

wchargin-branch: ci-cache-rust-pip
wchargin-source: 631d316bed4c17387901b166c6d8d28a6f8c8b7f
@wchargin wchargin requested a review from nfelt December 15, 2020 19:03
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
# Needed for installing binaries with cache
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't quite understand this comment. Could you elaborate slightly?

Update: read the other version of this comment which mentions cargo-raze so I assume this has something to do with raze generating these artifacts? Slightly more elaboration would still be useful IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Elaborated. This is needed only if you cargo install a binary, like
cargo-raze or hyperfine or something. Upstream documentation issue:
rust-lang/cargo#8841

We don’t actually need it for this job. I kept it to reduce headache in
case we later update it to cargo install. Clarified in comment.

@@ -116,6 +116,20 @@ jobs:
with:
python-version: '3.8'
architecture: 'x64'
- name: 'Cache Cargo home directory'
Copy link
Contributor

Choose a reason for hiding this comment

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

This also includes tensorboard/data/server/target/ which isn't the Cargo home directory (as I understand it) - maybe broaden description slightly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, yes. Renamed in both cases. (I think “Cargo artifacts” is probably
fine, since it’s Cargo (not rustc) that sets up this structure. But
happy to entertain other suggestions.)

wchargin-branch: ci-cache-rust-pip
wchargin-source: 588f30bc9fd70403a911ec482def0c0004f06aa3
Copy link
Contributor Author

@wchargin wchargin left a comment

Choose a reason for hiding this comment

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

thanks!

@@ -116,6 +116,20 @@ jobs:
with:
python-version: '3.8'
architecture: 'x64'
- name: 'Cache Cargo home directory'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, yes. Renamed in both cases. (I think “Cargo artifacts” is probably
fine, since it’s Cargo (not rustc) that sets up this structure. But
happy to entertain other suggestions.)

~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
# Needed for installing binaries with cache
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Elaborated. This is needed only if you cargo install a binary, like
cargo-raze or hyperfine or something. Upstream documentation issue:
rust-lang/cargo#8841

We don’t actually need it for this job. I kept it to reduce headache in
case we later update it to cargo install. Clarified in comment.

Copy link
Contributor

@nfelt nfelt left a comment

Choose a reason for hiding this comment

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

Ack, thanks for explaining.

@wchargin wchargin merged commit acac576 into master Dec 15, 2020
@wchargin wchargin deleted the wchargin-ci-cache-rust-pip branch December 15, 2020 20:36
@wchargin
Copy link
Contributor Author

I’ve just realized that this caching behavior is a little weird, albeit
benign. The cache key incorporates the Cargo.lock file and the CI
workflow file, not the actual Rust code. The cached data includes the
built dependencies, which depend only on Cargo.lock, and the cached
builds for our crates, rustboard_core and rustboard, which very
much depend on our code. So, on successive builds, the cache key may be
unchanged yet the cached outputs may differ. My understanding is that
when this happens, the cache is not updated.

I think that this is fine. Any change to the Rust code recompiles the
entire crate, so there’s no finer granularity possible. And it’s okay
that there’s not a functional dependency from the cache key to the exact
cache output, because any of the potential outputs for a given cache
key is an acceptable input for that cache key.

I’m inclined to take no action; just noting for posterity.

@wchargin wchargin added type:build/install and removed dependencies Pull requests that update a dependency file labels Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes core:rustboard //tensorboard/data/server/... theme:performance Performance, scalability, large data sizes, slowness, etc. type:build/install
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants