-
Notifications
You must be signed in to change notification settings - Fork 841
Add Zstandard compression support and update tests #12201
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
base: master
Are you sure you want to change the base?
Conversation
|
[approve ci] |
|
@masaori335 do you know which files I need to modify to install zstd on the osx used in the Jenkins job? |
|
We need to ask @ezelkow1 to install the package in the osx env, I guess. However, this PR has |
0167bf5 to
74cd8b5
Compare
thank you, _F was a mistake, it was meant to be _H |
308032c to
c598282
Compare
|
Looks like all the FreeBSD machines for CI are offline |
shukitchan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really appreciate it if you can please add some documentation to the changes.
Thanks.
|
Hi! This doesn't compile for me. I added a line to Please include this patch in your PR to enable the ZSTD code. Thanks! |
cmcfarlen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please patch ink_config.h and resolve compiler issues.
4b8603e to
72c0dbf
Compare
Code Review - ZSTD Compression ImplementationThank you for this excellent work on adding ZSTD compression support! The testing shows the feature works well and achieves great compression ratios (98.6%). I've completed a thorough code review and found a few issues that should be addressed before merging. 🔴 Critical IssueResource Management in
|
bryancall
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am ok with making the changes in this PR or create another PR, tests worked on my Fedora 42 server.
|
I'll make the changes in this pr if that's okay 👍 |
Adjusts the condition for suppressing Vary header checks on Accept-Encoding to only apply when explicitly configured by the operator
bryancall
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Summary - LGTM ✅
I've completed a thorough code review and functional testing of the zstd compression implementation.
Code Review
Implementation Quality:
- Clean separation of concerns with
zstd_compress.cc/hfollowing the existing compression plugin architecture - Proper resource management with context creation/destruction lifecycle
- Good error handling with input validation (null checks, size validation, progress detection)
- Uses modern zstd streaming API (
ZSTD_compressStream2) with appropriate flush handling - Checksum enabled for data integrity verification
- Configurable compression levels per host (1-22, default 12)
API & Integration:
- Proper addition of
TS_HTTP_VALUE_ZSTDandTS_HTTP_LEN_ZSTDconstants - Extends
normalize_aeconfiguration appropriately (values 4 and 5) - Consistent with existing gzip/brotli patterns
Build System:
- The CMake integration works well. Note: I needed to add a pkg-config fallback for Fedora/RHEL systems that don't ship zstd CMake configs, which you may want to consider for broader distribution compatibility.
Testing Results
Built and tested with dev-asan preset:
- ✅ Zstd compression confirmed working (98.6% reduction on 5KB text content)
- ✅ Content-Encoding header correctly set
- ✅ Compressed data verified as valid Zstandard format (v0.8+)
- ✅ Decompressed content matches original exactly
- ✅ Cache disabled mode works correctly
- ✅ No ASAN errors detected
Test Configuration:
- Origin serving 5,100 bytes of compressible text
- Compressed to 71 bytes on wire
- Level 12 compression
- Cache disabled for testing
Observations
- The Accept-Encoding cache quality calculation fix (commit
facf384) is a nice improvement that fixes the multiplicative quality issue - Documentation updates are comprehensive and include good examples
- All CI checks passing
Recommendation: This is a solid implementation that adds valuable functionality while maintaining code quality and backward compatibility. Ready to merge.
Fedora 43 Build SupportFor Fedora 43 (and potentially other RHEL-based systems), the zstd package doesn't ship CMake config files, only pkg-config files. Here's a suggested enhancement to add pkg-config fallback support: diff --git a/CMakeLists.txt b/CMakeLists.txt
index 692b11985a..0e1d26e08f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -365,7 +365,20 @@ if(zstd_FOUND)
endif()
endif()
else()
- set(HAVE_ZSTD_H FALSE)
+ # Try pkg-config as fallback
+ find_package(PkgConfig QUIET)
+ if(PKG_CONFIG_FOUND)
+ pkg_check_modules(ZSTD QUIET IMPORTED_TARGET libzstd)
+ if(ZSTD_FOUND)
+ add_library(zstd::zstd ALIAS PkgConfig::ZSTD)
+ set(HAVE_ZSTD_H TRUE)
+ message(STATUS "Found zstd via pkg-config: ${ZSTD_VERSION}")
+ else()
+ set(HAVE_ZSTD_H FALSE)
+ endif()
+ else()
+ set(HAVE_ZSTD_H FALSE)
+ endif()
endif()
# ncurses is used in traffic_topThis allows the build to find zstd on distributions that only provide |
@bryancall could this be done in a follow up or would we want this as part of the current pull request? |
|
@JakeChampion It can be done in a followup PR. I am thinking about merging this in today. |
cmcfarlen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is looking good. Thanks for hanging in there!
the original works fine
6d440f1
|
Apologies for the final commit here which voided the reviews, I saw a code refactor I previously did and realised doesn't need to happen at all so I reverted it, I'll not touch the pr again now |
| // Disable Vary mismatch checking for Accept-Encoding. This is only safe to | ||
| // set if you are promising to fix any Accept-Encoding/Content-Encoding mismatches. | ||
| if (http_config_params->get_ignore_accept_encoding_mismatch() && | ||
| // Only suppress variability checks when the operator explicitly set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a bug that's been here for a long time. @cmcfarlen @ezelkow1 I wonder if we should consider this for back ports to 10.x and even 9.2 ? Only this portion though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a pr open for this specific change which we can backport
#12618
| } | ||
|
|
||
| if (strncasecmp(value, "br", sizeof("br") - 1) == 0) { | ||
| info("Accept-Encoding value [%.*s]", len, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit picking (and I know it's the same), but this feels more like a debug() than an info(). I'm honestly not sure why this plugin has debug / info / warning all going to the same Dbg() tag.
This pull request adds full support for the zstd (Zstandard) compression algorithm throughout Apache Traffic Server, including build system integration, compression plugin support, Accept-Encoding header normalization, and test coverage.
Key Features
Build system and dependencies:
Findzstd.cmakelibzstd-devpackageTS_HAS_ZSTDfeature flag for conditional compilationCore compression support:
Accept-Encoding header normalization:
proxy.config.http.normalize_aeconfiguration to support values 4 and 5 for zstd normalizationAPI and infrastructure:
TS_HTTP_VALUE_ZSTDandTS_HTTP_LEN_ZSTDconstantsImproved cache matching:
Test Coverage
compress3.configfor zstd-specific plugin configurationStandards Compliance
The implementation follows RFC 8878 standards for zstd compression and maintains backward compatibility with existing gzip and brotli compression functionality. All tests pass and the feature is properly integrated with existing caching and content negotiation mechanisms.
Configuration
New normalization modes:
proxy.config.http.normalize_ae = 4: Prioritize zstd, fallback to br then gzipproxy.config.http.normalize_ae = 5: Support all combinations of zstd, br, and gzipBenefits