Skip to content

Cache compression - cross OS support #984

Closed

Description

@Phantsure

Problems

There have been multiple reported issues related to compression of caches. The issue we are looking to solve:

  • Cross-OS compatibility: Currently on windows cache uses a different compression algorithm (gzip) as compared to on linux | mac (zstd). This leads to different versions for caches created on different platforms. Therefore caches created on windows might not be recoverable on linux | mac. For more details on cache version see this.

Proposal

We are looking to solve both the problems as follows::

  • Change the default tar used on windows runners to GNUtar. This is already suggested as a workaround for people in these problems. Same tooling will ensure that cache can be reused across all three OSes.
  • Fallback to BSDtar with zstd on windows. BSDtar is already present on Windows runners by default but it does not use zstd due to the issue of compression hanging with large caches. In our testing, we found that performing archiving and compression as separate processes (instead of calling tar --use-compress-program) does not have the hang problem for caches of size up to 2GB.

Reasoning to choose GNUtar over BSDtar as default

BSDtar has some implementation problems. That’s the reason it stopped being used in MacOS for our action. For more details see actions/toolkit#552.

Related issues which should get fixed with this proposal

We have consolidated issues related to the above problems here. Feel free to provide feedback regarding these in this issue itself.

Activity

  1. mattjohnsonpint commented on Nov 16, 2022

    @mattjohnsonpint

    I'm glad this is being addressed, but I'm not sure the stated proposal is the right path forward. Or rather, it may be not the right path for all users.

    I don't believe that cross-OS compatibility of a single cache archive should be the primary driver, as it's quite common to put the runner.os in the cache key, as seen in the basic example in the docs. In my case, we need a different set of packages cached and restored for each OS, so we wouldn't use one common cache anyway.

    Also, it sounds as if the only plan for speeding things up on Windows is to switch to GNU tar. As I stated previously, and reported by others here and here - this has not resolved the problem. Cache restore is still very slow, even with GNU tar.

    I think the part that is missing from the proposal is that I believe there should be an option to choose the archive format, and that should be exposed all the way up to the cache action. Personally, I would like to use .7z as the format on Windows. Or perhaps just .zip, but still using 7-Zip to do the work because it's much faster than anything that ships with Windows itself, and it's already pre-installed on the GitHub Actions runner images.

  2. mattjohnsonpint commented on Nov 16, 2022

    @mattjohnsonpint

    BTW - 7-Zip does support tar and tar.gz formats. And like I said, it's pre-installed on both windows-2019 and windows-2022 runner images. I'm not certain if it would be faster than BSD or GNU tar or not. Perhaps you could experiment and see?

  3. lvpx commented on Nov 18, 2022

    @lvpx
    Contributor

    @mattjohnsonpint appreciate your feedback and suggestions on this. The stated proposal mainly addresses customer pain points surrounding reducing build time by leveraging cache across their runners. This proposal should also provide some performance improvements for windows as now the compression algo in use will be zstd instead gzip. We are also exploring other solutions for windows runner performance including 7-zip to provide better performance on windows when cross-os caching is not a concern.

  4. changed the title [-]Cache compression - cross OS support and better Windows performance[/-] [+]Cache compression - cross OS support[/+] on Nov 28, 2022
  5. Phantsure commented on Dec 5, 2022

    @Phantsure
    ContributorAuthor

    New beta release v3.1.0-beta

    We have released a beta version of cache under actions/cache@v3.1.0-beta for users to test for functionality. This should cache using GNU tar with zstd as compression and has BSD tar with zstd as fallback on windows. Functionality on linux | mac should remain same.

    Expected behaviour

    All the mentioned issues in above description should be resolved and not happening with this release. Performance might vary for different files on windows. No changes should happen to mac | linux cache performance

    Call outs

    • Old caches on windows wouldn't be recovered as different compression algorithm is used in beta.
    • Don't expect any or major performance improvement
  6. Phantsure commented on Dec 7, 2022

    @Phantsure
    ContributorAuthor

    👋🏼 Created a discussion for any feedback: #1019

  7. Safihre commented on Dec 7, 2022

    @Safihre

    You closed all the performance related issues and linked them to this, however, you say the patch will not resolve performance problems..
    So either fix the performance as well, or have a seperate tracker for the performance problems.

    Personally I've seen much more complaints about performance than requests for cross os caches.... So just like @mattjohnsonpint I am surprised about the priorities here.

  8. bishal-pdMSFT commented on Dec 8, 2022

    @bishal-pdMSFT

    @Safihre that's correct. We started by thinking to tackle both cross-os and performance problems together but realized that performance needs a more in-depth and targeted approach and needs more time. That's why we will first ship out the cross-os support. We have a separate internal tracker for performance problem. Will create a public tracker as well once we more details to share.

  9. 1 remaining item

  10. Phantsure commented on Dec 23, 2022

    @Phantsure
    ContributorAuthor

    Update

    Have released all the changes to v3. Now cache would be able to work cross os. Go ahead to release notes for details on what new is added: https://github.com/actions/cache/blob/main/RELEASES.md#321
    Keeping this issue open for sometime for feedback

  11. Phantsure commented on Dec 27, 2022

    @Phantsure
    ContributorAuthor

    Update

    We have reverted the changes due to multiple complains regarding symlinks not working. If a cache containing symlink is saved on linux|mac and restored on windows then GNU tar not able to recover those symlinks. We are actively working to resolve this issue, till then have reverted the changes.

    Related issue: #1043

  12. Phantsure commented on Jan 5, 2023

    @Phantsure
    ContributorAuthor

    Update

    Currently we are fixing a problem related to symlinks creation on windows during a tarball extraction which was created on linux|mac. Common example is caching a node_modules folder. Original issue which was reported and lead to reverting original changes.

    Solution:

    We found that symlink creation is handled differently for different platforms and filesystems. We encountered two solutions to handle this:

    • Use --dereference with tar on creation to remove any symlinks present while creation:
      • Pros: Removed symlinks entirely while creation so no problem while handling
      • Cons: Size of tar would increase as this would create copies of same file.
    • Add environment variable MSYS=winsymlinks:nativestrict to handle symlinks as per windows symlink: Blog. This works for any tar based on msys2 platform, which is our current tar from git-for-windows.
      • Pros: Creates a symlink for any unix based symlink so should work as usual.
      • Cons: Might break if symlink created is still not handled by code. So user should still understand that symlinks on cross os caches might break.

    We have chosen to go with 2nd solution and would love hear feedback from community.

  13. rfay commented on Jan 5, 2023

    @rfay

    I believe that MSYS=winsymlinks:nativestrict is a great way to go, assuming using git-bash of course. Older windows systems also have to have the "Developer mode" set for this to work, I'm not sure whether that is still a problem.

  14. bishal-pdMSFT commented on Jan 5, 2023

    @bishal-pdMSFT

    Hosted runners do run with administrative privileges so this should be fine

  15. Phantsure commented on Jan 9, 2023

    @Phantsure
    ContributorAuthor

    Update

    We have released new changes with symlink issue fixed and allowing to use cross-os cache as an opt-in feature by adding enableCrossOsArchive input as true to cache action.
    Note: All previous workflows should work as usual with cache miss for first time on windows due version changes done. This was done to keep previous workflows on windows cache separate as compared to cross-os cache.

  16. mkht commented on Jan 10, 2023

    @mkht

    I encountered a problem when restoring a cache saved by windows-latest with a self-hosted runner in Windows Server 2016.
    After some research I found here and was able to solve the problem by installing GNU tar and zstd on the runner.

    It would be helpful if it be documented that these installations are required (or recommended?) when using cache actions in a self-hosted runner.

  17. lvpx commented on Jan 10, 2023

    @lvpx
    Contributor

    Hi @mkht, thank you for this feedback. We had these documented previously in the workarounds section, we'll have these added to Pre-requisites moving forward for better visibility.

  18. maybeec commented on Jan 12, 2023

    @maybeec
    Contributor

    @mkht I think GNU tar already comes with Git installation: #576 (comment)

    At least for my workflows this works fine: https://github.com/devonfw-actions/java-maven-setup/blob/main/action.yml#L53

  19. mkht commented on Jan 12, 2023

    @mkht

    Hi @maybeec , thanks for the advice.

    As odd as it may seem, Git is not installed on my self-hosted runner.
    To keep the maintenance of the runner easily, I only install the minimum number of applications that are necessary.

    As far as I know, there is no mention of Git being required for the self-hosted runner to work. The lack of Git has not caused any fatal problems in the past.
    https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners#requirements-for-self-hosted-runner-machines

  20. lvpx commented on Jan 12, 2023

    @lvpx
    Contributor

    Hi @mkht, so we have added gnutar and zstd as pre-requisites to the README. Closing this issue. Thank you everyone for the feedback and suggestions.

  21. unpinned this issue on Jan 31, 2023
  22. alena-bot commented on Oct 3, 2024

    @alena-bot

    Проблема с hht/404

  23. alena-bot commented on Oct 3, 2024

    @alena-bot

    Кто нибудь может помочь? пожалуйста

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions