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

Add zstd http channel output compression #30297

Open
bmarwell opened this issue Nov 26, 2024 · 2 comments
Open

Add zstd http channel output compression #30297

bmarwell opened this issue Nov 26, 2024 · 2 comments
Labels
enhancement Feature Request: External A feature request opened by an external contributor. Should not be used by Open Liberty developers. Needs member attention

Comments

@bmarwell
Copy link
Contributor

bmarwell commented Nov 26, 2024

Describe the use case that you want to enable:

Currently, for compression (see #30295 and https://openliberty.io/docs/latest/reference/config/compression.html), only those options are available:

  • identity (no compression)
  • deflate aka zlib
  • gzip / gzip (same, but with more headers and different checksum)

Common browser requests include:

Accept-Encoding: gzip, deflate, br, zstd

Thus, brotli and zstd would be viable options to add.

However, brotli is not that wide-spread, e.g. it is not part of the AIX toolbox while zstd is.
Brotli is usually not in the base packages of most linux distributions, while zstd nowadays is more likely part of it.
zstd also gives consistently better compression for less time in my experience.

Describe why this is important to you:

Using gzip and/or deflate is a waste of CPU compared to modern algorithms.
If many Open Liberty users adapted this, a lot of CPU cycles would be saved world wide.

Additional context

Here is a sample compressing a 7 MiB javascript file (chunk - vendors), typically delivered from any random web app.

As you can see, even the optimized AIX version is not on par with zstd, lz4 is not widely supported by browsers which doesn't make it a viable option either.
This test is not representative in any means, YMMV.

Results Mac M1

Algo     Level    Time        Size      Size %
Baseline             0      7666149    100,0000%
lz4        1        33      3291830     42,9398%
gzip       6       281      2035493     26,5517%
zstd       3        57      2085469     27,2036%
zstd       6       107      1879736     24,5200%
zlib       6        56      2036878     26,5698%

Results AIX 7.3

Algo     Level    Time        Size      Size %
Baseline             0      7666149    100,0000%
lz4        1        78      3287607     42,8847%
gzip       6       466      2036606     26,5662%
zstd       3        77      2085469     27,2036%
zstd       6       163      1878754     24,5071%
gz pigz    6       179      2615102     34,1123%

Results Linux SLES15

Algo     Level    Time        Size      Size %
Baseline             0      7666149    100,0000%
lz4        1        47      3291830     42,9398%
gzip       6       487      2036606     26,5662%
zstd       3        73      2097140     27,3558%
zstd       6       146      1878754     25,6630%
gz pigz    6        78      2036606     26,5662%

IBM Ideas

https://ideas.ibm.com/ideas/LIBERTY-I-144

@bmarwell bmarwell added the Feature Request: External A feature request opened by an external contributor. Should not be used by Open Liberty developers. label Nov 26, 2024
@bmarwell
Copy link
Contributor Author

bmarwell commented Nov 26, 2024

zstd is available from either this resource: https://github.com/luben/zstd-jni or using apache commons (using the same library as a backend implementation).
It might not be available on AIX, but if AIX used another library as a fallback, that would be sufficient.

For zstd's compression level, 3 seems to be a reasonable value. While 5 is smaller than gzip, it already almost doubles compression time (real time). 4 is not significantly smaller and probably not worth if for 50% more time consumption.

There is also: https://github.com/airlift/aircompressor/tree/master (but I never used it, might be a reasonable fallback for AIX if AIX could not load the shared obj).

@bmarwell
Copy link
Contributor Author

bmarwell commented Dec 4, 2024

There is actually an implementation using the Java 22 Foreign Function & Memory API:
https://github.com/LWJGL/lwjgl3

Available as a Maven Artefact here: https://search.maven.org/artifact/org.lwjgl/lwjgl-zstd/3.3.4/jar

I wouldn't mind if this feature was "JDK 22+ only".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature Request: External A feature request opened by an external contributor. Should not be used by Open Liberty developers. Needs member attention
Projects
None yet
Development

No branches or pull requests

3 participants