From 7e7820edca6a8705aa34b003aac6f76fcb594c13 Mon Sep 17 00:00:00 2001 From: Lovepreet Singh Date: Thu, 25 Aug 2022 05:52:10 +0000 Subject: [PATCH 1/5] Move Cache segment restore timeout to Known practices and workarounds --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c495595..9cbace0 100644 --- a/README.md +++ b/README.md @@ -223,15 +223,15 @@ jobs: if: steps.cache-primes.outputs.cache-hit != 'true' run: ./generate-primes -d prime-numbers ``` -## Cache segment restore timeout - -A cache gets downloaded in multiple segments of fixed sizes (`1GB` for a `32-bit` runner and `2GB` for a `64-bit` runner). Sometimes, a segment download gets stuck which causes the workflow job to be stuck forever and fail. Version `v3.0.8` of `actions/cache` introduces a segment download timeout. The segment download timeout will allow the segment download to get aborted and hence allow the job to proceed with a cache miss. Default value of this timeout is 60 minutes and can be customized by specifying an [environment variable](https://docs.github.com/en/actions/learn-github-actions/environment-variables) named `SEGMENT_DOWNLOAD_TIMEOUT_MINS` with timeout value in minutes. ## Known practices and workarounds Following are some of the known practices/workarounds which community has used to fulfill specific requirements. You may choose to use them if suits your use case. Note these are not necessarily the only or the recommended solution. +#### Cache segment restore timeout +A cache gets downloaded in multiple segments of fixed sizes (`1GB` for a `32-bit` runner and `2GB` for a `64-bit` runner). Sometimes, a segment download gets stuck which causes the workflow job to be stuck forever and fail. Version `v3.0.8` of `actions/cache` introduces a segment download timeout. The segment download timeout will allow the segment download to get aborted and hence allow the job to proceed with a cache miss. + #### Update a cache A cache today is immutable and cannot be updated. But some use cases require the cache to be saved even though there was a "hit" during restore. To do so, use a `key` which is unique for every run and use `restore-keys` to restore the nearest cache. For example: ``` From eb8b610ee6aa7053a5628f75610a7e9b32eb2278 Mon Sep 17 00:00:00 2001 From: Lovepreet Singh Date: Thu, 25 Aug 2022 13:14:23 +0000 Subject: [PATCH 2/5] Add zstd workaround to README. Add yaml formatting to code blocks. Move Cache segment restore to Known Practices section. --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9cbace0..a5bb1b8 100644 --- a/README.md +++ b/README.md @@ -234,7 +234,7 @@ A cache gets downloaded in multiple segments of fixed sizes (`1GB` for a `32-bit #### Update a cache A cache today is immutable and cannot be updated. But some use cases require the cache to be saved even though there was a "hit" during restore. To do so, use a `key` which is unique for every run and use `restore-keys` to restore the nearest cache. For example: - ``` + ```yaml - name: update cache on every commit uses: actions/cache@v3 with: @@ -248,6 +248,23 @@ A cache today is immutable and cannot be updated. But some use cases require the #### Use cache across feature branches Reusing cache across feature branches is not allowed today to provide cache [isolation](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache). However if both feature branches are from the default branch, a good way to achieve this is to ensure that the default branch has a cache. This cache will then be consumable by both feature branches. +#### Improving cache restore performance on Windows +Currently, cache restore is slow on Windows due to both tar being slow and the compression algorithm being used is `gzip`. Zstd was disabled on windows due to issues with bsd tar(libarchive) which is the tar implementation in use on Windows. To improve cache restore performance, we can re-enable `zstd` as the compression algorithm using the following workaround by using GNU tar instead. + +Add the following step to your workflow before the cache step: + +```yaml + - if: ${{ runner.os == 'Windows' }} + name: Use GNU tar + shell: cmd + run: | + echo "Adding GNU tar to PATH" + echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%" +``` + +This should work on all Github Hosted runners as it is. For self-hosted runners, please ensure you have GNU tar and `zstd` installed. + + ## Contributing We would love for you to contribute to `actions/cache`, pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information. From 7b5e3aaf2315cff6148150b4617902b322cee63d Mon Sep 17 00:00:00 2001 From: Lovepreet Singh Date: Thu, 25 Aug 2022 13:18:15 +0000 Subject: [PATCH 3/5] Move remaining section of Cache segment restore timeout --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a5bb1b8..9c21246 100644 --- a/README.md +++ b/README.md @@ -224,14 +224,14 @@ jobs: run: ./generate-primes -d prime-numbers ``` -Default value of this timeout is 60 minutes and can be customized by specifying an [environment variable](https://docs.github.com/en/actions/learn-github-actions/environment-variables) named `SEGMENT_DOWNLOAD_TIMEOUT_MINS` with timeout value in minutes. - ## Known practices and workarounds Following are some of the known practices/workarounds which community has used to fulfill specific requirements. You may choose to use them if suits your use case. Note these are not necessarily the only or the recommended solution. #### Cache segment restore timeout A cache gets downloaded in multiple segments of fixed sizes (`1GB` for a `32-bit` runner and `2GB` for a `64-bit` runner). Sometimes, a segment download gets stuck which causes the workflow job to be stuck forever and fail. Version `v3.0.8` of `actions/cache` introduces a segment download timeout. The segment download timeout will allow the segment download to get aborted and hence allow the job to proceed with a cache miss. +Default value of this timeout is 60 minutes and can be customized by specifying an [environment variable](https://docs.github.com/en/actions/learn-github-actions/environment-variables) named `SEGMENT_DOWNLOAD_TIMEOUT_MINS` with timeout value in minutes. + #### Update a cache A cache today is immutable and cannot be updated. But some use cases require the cache to be saved even though there was a "hit" during restore. To do so, use a `key` which is unique for every run and use `restore-keys` to restore the nearest cache. For example: ```yaml From a057257949027ef0a098a96885fda11cc9b1b929 Mon Sep 17 00:00:00 2001 From: Lovepreet Singh Date: Fri, 26 Aug 2022 09:00:35 +0000 Subject: [PATCH 4/5] Add cross-os caching to the zstd workaround section. --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9c21246..503987b 100644 --- a/README.md +++ b/README.md @@ -248,10 +248,10 @@ A cache today is immutable and cannot be updated. But some use cases require the #### Use cache across feature branches Reusing cache across feature branches is not allowed today to provide cache [isolation](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache). However if both feature branches are from the default branch, a good way to achieve this is to ensure that the default branch has a cache. This cache will then be consumable by both feature branches. -#### Improving cache restore performance on Windows -Currently, cache restore is slow on Windows due to both tar being slow and the compression algorithm being used is `gzip`. Zstd was disabled on windows due to issues with bsd tar(libarchive) which is the tar implementation in use on Windows. To improve cache restore performance, we can re-enable `zstd` as the compression algorithm using the following workaround by using GNU tar instead. +#### Improving cache restore performance on Windows/Using cross-os caching +Currently, cache restore is slow on Windows due to tar being inherently slow and the compression algorithm `gzip` in use. `zstd` is the default algorithm in use on linux and macos. It was disabled on Windows due to issues with bsd tar(libarchive), the tar implementation in use on Windows. -Add the following step to your workflow before the cache step: +To improve cache restore performance, we can re-enable `zstd` as the compression algorithm using the following workaround. Add the following step to your workflow before the cache step: ```yaml - if: ${{ runner.os == 'Windows' }} @@ -262,8 +262,9 @@ Add the following step to your workflow before the cache step: echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%" ``` -This should work on all Github Hosted runners as it is. For self-hosted runners, please ensure you have GNU tar and `zstd` installed. +The `cache` action will use GNU tar instead of bsd tar on Windows. This should work on all Github Hosted runners as it is. For self-hosted runners, please ensure you have GNU tar and `zstd` installed. +The above workaround is also needed if you wish to use cross-os caching since difference of compression algorithms will result in different cache versions for the same cache key. So the above workaround will ensure `zstd` is used for caching on all platforms thus resulting in the same cache version for the same cache key. ## Contributing We would love for you to contribute to `actions/cache`, pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information. From 471fb0c87e5d7210f339d8ea2e01505ddafd793d Mon Sep 17 00:00:00 2001 From: Lovepreet Singh Date: Tue, 30 Aug 2022 08:24:10 +0000 Subject: [PATCH 5/5] Move workarounds to a different file --- README.md | 42 ++++-------------------------------------- workarounds.md | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 38 deletions(-) create mode 100644 workarounds.md diff --git a/README.md b/README.md index 503987b..4e07b93 100644 --- a/README.md +++ b/README.md @@ -227,44 +227,10 @@ jobs: ## Known practices and workarounds Following are some of the known practices/workarounds which community has used to fulfill specific requirements. You may choose to use them if suits your use case. Note these are not necessarily the only or the recommended solution. -#### Cache segment restore timeout -A cache gets downloaded in multiple segments of fixed sizes (`1GB` for a `32-bit` runner and `2GB` for a `64-bit` runner). Sometimes, a segment download gets stuck which causes the workflow job to be stuck forever and fail. Version `v3.0.8` of `actions/cache` introduces a segment download timeout. The segment download timeout will allow the segment download to get aborted and hence allow the job to proceed with a cache miss. - -Default value of this timeout is 60 minutes and can be customized by specifying an [environment variable](https://docs.github.com/en/actions/learn-github-actions/environment-variables) named `SEGMENT_DOWNLOAD_TIMEOUT_MINS` with timeout value in minutes. - -#### Update a cache -A cache today is immutable and cannot be updated. But some use cases require the cache to be saved even though there was a "hit" during restore. To do so, use a `key` which is unique for every run and use `restore-keys` to restore the nearest cache. For example: - ```yaml - - name: update cache on every commit - uses: actions/cache@v3 - with: - path: prime-numbers - key: primes-${{ runner.os }}-${{ github.run_id }} # Can use time based key as well - restore-keys: | - primes-${{ runner.os }} - ``` - Please note that this will create a new cache on every run and hence will consume the cache [quota](#cache-limits). - -#### Use cache across feature branches -Reusing cache across feature branches is not allowed today to provide cache [isolation](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache). However if both feature branches are from the default branch, a good way to achieve this is to ensure that the default branch has a cache. This cache will then be consumable by both feature branches. - -#### Improving cache restore performance on Windows/Using cross-os caching -Currently, cache restore is slow on Windows due to tar being inherently slow and the compression algorithm `gzip` in use. `zstd` is the default algorithm in use on linux and macos. It was disabled on Windows due to issues with bsd tar(libarchive), the tar implementation in use on Windows. - -To improve cache restore performance, we can re-enable `zstd` as the compression algorithm using the following workaround. Add the following step to your workflow before the cache step: - -```yaml - - if: ${{ runner.os == 'Windows' }} - name: Use GNU tar - shell: cmd - run: | - echo "Adding GNU tar to PATH" - echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%" -``` - -The `cache` action will use GNU tar instead of bsd tar on Windows. This should work on all Github Hosted runners as it is. For self-hosted runners, please ensure you have GNU tar and `zstd` installed. - -The above workaround is also needed if you wish to use cross-os caching since difference of compression algorithms will result in different cache versions for the same cache key. So the above workaround will ensure `zstd` is used for caching on all platforms thus resulting in the same cache version for the same cache key. +- [Cache segment restore timeout](./workarounds.md#cache-segment-restore-timeout) +- [Update a cache](./workarounds.md#update-a-cache) +- [Use cache across feature branches](./workarounds.md#use-cache-across-feature-branches) +- [Improving cache restore performance on Windows/Using cross-os caching](./workarounds.md#improving-cache-restore-performance-on-windows-using-cross-os-caching) ## Contributing We would love for you to contribute to `actions/cache`, pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information. diff --git a/workarounds.md b/workarounds.md new file mode 100644 index 0000000..443bafc --- /dev/null +++ b/workarounds.md @@ -0,0 +1,38 @@ +#### Cache segment restore timeout +A cache gets downloaded in multiple segments of fixed sizes (`1GB` for a `32-bit` runner and `2GB` for a `64-bit` runner). Sometimes, a segment download gets stuck which causes the workflow job to be stuck forever and fail. Version `v3.0.8` of `actions/cache` introduces a segment download timeout. The segment download timeout will allow the segment download to get aborted and hence allow the job to proceed with a cache miss. + +Default value of this timeout is 60 minutes and can be customized by specifying an [environment variable](https://docs.github.com/en/actions/learn-github-actions/environment-variables) named `SEGMENT_DOWNLOAD_TIMEOUT_MINS` with timeout value in minutes. + +#### Update a cache +A cache today is immutable and cannot be updated. But some use cases require the cache to be saved even though there was a "hit" during restore. To do so, use a `key` which is unique for every run and use `restore-keys` to restore the nearest cache. For example: + ```yaml + - name: update cache on every commit + uses: actions/cache@v3 + with: + path: prime-numbers + key: primes-${{ runner.os }}-${{ github.run_id }} # Can use time based key as well + restore-keys: | + primes-${{ runner.os }} + ``` + Please note that this will create a new cache on every run and hence will consume the cache [quota](#cache-limits). + +#### Use cache across feature branches +Reusing cache across feature branches is not allowed today to provide cache [isolation](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache). However if both feature branches are from the default branch, a good way to achieve this is to ensure that the default branch has a cache. This cache will then be consumable by both feature branches. + +#### Improving cache restore performance on Windows/Using cross-os caching +Currently, cache restore is slow on Windows due to tar being inherently slow and the compression algorithm `gzip` in use. `zstd` is the default algorithm in use on linux and macos. It was disabled on Windows due to issues with bsd tar(libarchive), the tar implementation in use on Windows. + +To improve cache restore performance, we can re-enable `zstd` as the compression algorithm using the following workaround. Add the following step to your workflow before the cache step: + +```yaml + - if: ${{ runner.os == 'Windows' }} + name: Use GNU tar + shell: cmd + run: | + echo "Adding GNU tar to PATH" + echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%" +``` + +The `cache` action will use GNU tar instead of bsd tar on Windows. This should work on all Github Hosted runners as it is. For self-hosted runners, please ensure you have GNU tar and `zstd` installed. + +The above workaround is also needed if you wish to use cross-os caching since difference of compression algorithms will result in different cache versions for the same cache key. So the above workaround will ensure `zstd` is used for caching on all platforms thus resulting in the same cache version for the same cache key. \ No newline at end of file