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

Prefer zstd over gzip #270

Merged
merged 3 commits into from May 4, 2020
Merged

Prefer zstd over gzip #270

merged 3 commits into from May 4, 2020

Conversation

@aiqiaoy
Copy link
Contributor

@aiqiaoy aiqiaoy commented Apr 23, 2020

Fixes #184

A lot of the work was completed by @imbsky in PR #202. Additionally, this PR adds:

  • zstd in the cache version
  • A gzip fallback path for self-hosted runners that do not have zstd installed
  • Jest tests
@smorimoto
Copy link
Contributor

@smorimoto smorimoto commented Apr 23, 2020

Awesome @aiqiaoy!! I will review this PR soon 🙂 Thanks for your work!

@smorimoto
Copy link
Contributor

@smorimoto smorimoto commented Apr 23, 2020

Perhaps you should pick this commit (c7743bc) change to make the test work correctly. (zstd is not installed by default in ubuntu:latest, which is currently used for proxy-related testing. So, for testing, I just created an image of ubuntu:latest with zstd, so we can use it to test.)

@@ -82,12 +83,11 @@ function createHttpClient(): HttpClient {
);
}

export function getCacheVersion(): string {
export function getCacheVersion(useZstd?: boolean): string {

This function is a "boolean-trap". It might be worth considering using an enum here, like:

enum CompressionTool {
	Zstd,
	GnuTar
}

Copy link
Contributor

@smorimoto smorimoto Apr 27, 2020

Well, in my opinion, this is not a big deal. The enum has mistakes, depending on how you look at it, and should not be actively recommended for use. If you want to avoid use boolean, you should use string literal types combine with union types. But it's too overkill for this purpose. So, there is no problem with the current code.

Never said that it is a big deal :)

I was more coming from a readability-PoV because the first change I saw in the PR diff was:

test("getCacheVersion with zstd compression returns version", async () => {
    testUtils.setInput(Inputs.Path, "node_modules");

    const result = getCacheVersion(true);

    expect(result).toEqual(
        "273877e14fd65d270b87a198edbfa2db5a43de567c9a548d2a2505b408befe24"
    );
});

and I didn't understand what getCacheVersion(true) means, hence the comment about boolean-traps :)

Copy link
Contributor

@smorimoto smorimoto Apr 28, 2020

Sorry. This kind of expression is really common in Japanese, So I said. (English is still difficult for me...) It certainly seems to have a readability problem, but I think it's basically within the acceptable range.

Copy link
Contributor

@smorimoto smorimoto Apr 28, 2020

If this needs to be changed, I suggest a major redesign, but it requires too much work and this action probably won't be a large codebase that it needs.

Copy link
Contributor Author

@aiqiaoy aiqiaoy Apr 28, 2020

PR updated to use enum instead.

.github/workflows/workflow.yml Outdated Show resolved Hide resolved
@aiqiaoy aiqiaoy marked this pull request as draft Apr 27, 2020
@aiqiaoy aiqiaoy force-pushed the users/aiyan/zstd branch from c69540a to 619a527 Apr 27, 2020
@smorimoto
Copy link
Contributor

@smorimoto smorimoto commented Apr 27, 2020

@aiqiaoy This should work.

const args = [
  ...(useZstd ? ["--use-compress-program", "zstd -T0 --long=31"] : ["-z"]),
  "-xf",
  archivePath.replace(new RegExp("\\" + path.sep, "g"), "/"),
  "-P",
  "-C",
  workingDirectory.replace(new RegExp("\\" + path.sep, "g"), "/"),
];

@smorimoto
Copy link
Contributor

@smorimoto smorimoto commented Apr 27, 2020

This isn't a tar problem, it's a strange specification of Node.js.

@aiqiaoy
Copy link
Contributor Author

@aiqiaoy aiqiaoy commented Apr 28, 2020

@aiqiaoy This should work.

const args = [
  ...(useZstd ? ["--use-compress-program", "zstd -T0 --long=31"] : ["-z"]),
  "-xf",
  archivePath.replace(new RegExp("\\" + path.sep, "g"), "/"),
  "-P",
  "-C",
  workingDirectory.replace(new RegExp("\\" + path.sep, "g"), "/"),
];

@imbsky Thanks! Nodejs newbie here and you definitely saved me a lot of headaches lol

@smorimoto
Copy link
Contributor

@smorimoto smorimoto commented Apr 28, 2020

My pleasure. I had the same experience before when implementing this hehe...

@smorimoto
Copy link
Contributor

@smorimoto smorimoto commented Apr 28, 2020

The format check seems to have failed.

@aiqiaoy aiqiaoy marked this pull request as ready for review Apr 28, 2020
@smorimoto
Copy link
Contributor

@smorimoto smorimoto commented Apr 29, 2020

Oh, all tests have passed now. I will review this soon. Perhaps you are also interested in doing that. @joshmgross

Copy link
Member

@joshmgross joshmgross left a comment

Looks good overall! Left some clarifying comments

src/cacheHttpClient.ts Outdated Show resolved Hide resolved
src/tar.ts Outdated Show resolved Hide resolved
src/tar.ts Outdated Show resolved Hide resolved
src/utils/actionUtils.ts Outdated Show resolved Hide resolved
@smorimoto
Copy link
Contributor

@smorimoto smorimoto commented Apr 29, 2020

All of the following flags are needed for compression,

zstd -T0 --long=31

and all of the following flags are needed for a decompression.

zstd --long=31 -d

CC: @kcgen

@smorimoto
Copy link
Contributor

@smorimoto smorimoto commented Apr 29, 2020

This explanation by @kcgen is really impressive.
#184 (comment)

@aiqiaoy
Copy link
Contributor Author

@aiqiaoy aiqiaoy commented Apr 29, 2020

All of the following flags are needed for compression,

zstd -T0 --long=31

and all of the following flags are needed for a decompression.

zstd --long=31 -d

The doc says the maximum for --long is 30 (1 GiB) on 32-bit platforms and 31 (2 GiB) on 64-bit platforms.

@joshmgross Do you know if we support 32 bits OS for our self-hosted runners?

@joshmgross
Copy link
Member

@joshmgross joshmgross commented Apr 30, 2020

@joshmgross Do you know if we support 32 bits OS for our self-hosted runners?

Yep we do. We at least have an ARM32 Runner that's in Pre-Release

Add zstd to cache versioning
@aiqiaoy aiqiaoy force-pushed the users/aiyan/zstd branch 2 times, most recently from 8e1ec33 to 76bba55 Apr 30, 2020
@aiqiaoy aiqiaoy force-pushed the users/aiyan/zstd branch from 76bba55 to a5d9a3b May 1, 2020
@aiqiaoy
Copy link
Contributor Author

@aiqiaoy aiqiaoy commented May 1, 2020

PR updated.

@joshmgross @imbsky It would be great if you can take a look again when you have time :)

Copy link
Member

@joshmgross joshmgross left a comment

Awesome! 🚢

src/tar.ts Outdated Show resolved Hide resolved
@smorimoto
Copy link
Contributor

@smorimoto smorimoto commented May 1, 2020

This looks good to me! I really appreciate your work!

@aiqiaoy
Copy link
Contributor Author

@aiqiaoy aiqiaoy commented May 1, 2020

Thanks everyone for the review and feedback. I'll check this PR in early Monday just to be on the safer side.

Copy link
Contributor

@smorimoto smorimoto left a comment

Looks good to me!

@aiqiaoy aiqiaoy merged commit 9eb452c into master May 4, 2020
11 checks passed
11 checks passed
@github-actions[bot]
build (ubuntu-latest)
Details
@github-actions[bot]
build (windows-latest)
Details
@github-actions[bot]
build (macOS-latest)
Details
@github-actions[bot]
test-save (ubuntu-latest)
Details
@github-actions[bot]
test-save (windows-latest)
Details
@github-actions[bot]
test-save (macOS-latest)
Details
@github-actions[bot]
test-proxy-save
Details
@github-actions[bot]
test-restore (ubuntu-latest)
Details
@github-actions[bot]
test-restore (windows-latest)
Details
@github-actions[bot]
test-restore (macOS-latest)
Details
@github-actions[bot]
test-proxy-restore
Details
@smorimoto
Copy link
Contributor

@smorimoto smorimoto commented May 4, 2020

Thanks @aiqiaoy for doing the rest of the work.
Thanks @miketimofeev for helping me make changes to the infrastructure.
and kudos to @kcgen for helping me most with this change.
Thank you all!

@shunkakinoki
Copy link

@shunkakinoki shunkakinoki commented May 4, 2020

It is way faster, thank you!

@smorimoto
Copy link
Contributor

@smorimoto smorimoto commented May 4, 2020

@joshmgross Is there anything left to do for the v2 or next v1 series release?

@smorimoto
Copy link
Contributor

@smorimoto smorimoto commented May 4, 2020

If I remember correctly, the multi path stuff and this were the only remaining tasks for v2.

@joshmgross
Copy link
Member

@joshmgross joshmgross commented May 4, 2020

@joshmgross Is there anything left to do for the v2 or next v1 series release?

We're tracking #263 for v2, but that might be back-ported to v1 as well.

@smorimoto
Copy link
Contributor

@smorimoto smorimoto commented May 4, 2020

Oh, I see. Will the next version probably be released after the PR is merged?

@smorimoto
Copy link
Contributor

@smorimoto smorimoto commented May 4, 2020

Well, I just want to check, so there is no rush to do anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants