-
Notifications
You must be signed in to change notification settings - Fork 706
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
Added support for zstd compression #1247
Added support for zstd compression #1247
Conversation
src/common/http.cc
Outdated
// Allocate a smart buffer to contain compressed data... | ||
std::unique_ptr compressedData = std::make_unique<std::byte[]>(estimated_size); | ||
|
||
// Compress data using compresion_level = 5: https://facebook.github.io/zstd/zstd_manual.html#Chapter5 |
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.
We currently don't have a public API for the user to specify the compression level (each compressor can use a different range). Until we figure out an elegant way to do that, it might be best to set the compression level consistent with whatever we're using on the others (I think max).
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 believe max is really max on zstd. We could also set compression level dynamically, or partially dynamically, taking into account available CPU bandwidth, available network bandwidth, number of cores (zstd is good with multithreading) etc.
But maybe a middling value is wisest until we do a well-thought-through API/algorithm for compression level?
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.
@dgreatwood @kiplingw I agree. Using a middle value makes the most sense to me. At least until we find a better solution as both of you guys mentioned.
@@ -77,7 +81,8 @@ foreach test_name : pistache_test_files | |||
gmock_dep, | |||
curl_dep, | |||
cpp_httplib_dep, | |||
brotli_dep | |||
brotli_dep, | |||
zstd_dep |
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.
Remember that libzstd-dev
also needs to be added to Build-Depends
in debian/control
. That's in a separate branch and so you'll need a separate PR for that.
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.
Hi @EdgarModesto23 -
I see a number of the github workflows (https://github.com/pistacheio/pistache/actions) are failing, e.g. with:
tests/meson.build:71:1: ERROR: Unknown variable "zstd_dep".
Some of that may be related to the need for an update to debian/control. Certainly the way brotli is dealt with should be a good model.
The workflows linuxflibev, linux and macOS libevent should all pass (occasionally the debian:testing tests under linux workflow will fail if debian:testing is in a funny state, but in fact it seems OK at present). The conventional-commits and abidiff are less important (just make sure you bump version number if abidiff changes).
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.
Regarding http_server_test.cpp -
There are a lot of formatting changes that amount to indenting code that lies within encapsulating (scope limiting) curly braces, like:
{ // encapsulate
// Indent this line by 4 more spaces
// Etc.
}
The extra indentation that has been added is 100% logical, however it was not added before so that the encapsulating braces can be added or removed without causing a "diff" for each of the enclosed lines.
Would it be practical to revert the formatting changes from http_server_test.cpp, leaving only the substantive changes to be reviewed?
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1247 +/- ##
==========================================
- Coverage 76.29% 76.26% -0.04%
==========================================
Files 58 58
Lines 10027 9698 -329
==========================================
- Hits 7650 7396 -254
+ Misses 2377 2302 -75 ☔ View full report in Codecov by Sentry. |
@Tachi107, your feedback is appreciated. |
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've left some feedback in a few different comments, check it out!
Also, the 1.5.6 release of zstd seems to have specific improvements to usage in web contexts. You might want to see what changed and evaluate if tweaking your implementation is worthwhile.
@Tachi107 and @dgreatwood, looks fine to me. |
@EdgarModesto23, please review our PPA's build log. Your PR seems to break on all architectures on jammy. Here's is the log for amd64. Can you look into your build dependencies? If we can't satisfy Jammy, we will have to either drop it, or at least find a way to disable support for it in Jammy in |
@kiplingw I'll fix it right away. |
@kiplingw I made a PR that should fix the problem. I'll stay around in case anything comes up. Thank you for reaching out! |
Hi @EdgarModesto23 - May I raise another question / concern, this time about the test code? In your http_server_test.cc/server_with_content_encoding_zstd, you have:
Here are my concerns:
In short, it seems that ZSTD_getFrameContentSize should act on newlyCompressedResponse, and then ZSTD_getFrameContentSize's return code should be checked. I included this code:
(cf. https://github.com/dgreatwood/pistachefork/blob/windows/tests/http_server_test.cc) Could you please review the comments above and likewise my proposed code? Thanks much! |
Following #1200
This patch adds support for zstd compression and it updates build scripts and the main README to include the new -DPISTACHE_USE_CONTENT_ENCODING_ZSTD flag. I mostly followed the style suggested by @kiplingw on #1177 and #1178.
It uses version 1.5.6 of the C implementation of zstd library.