Repository navigation
advertise transport encoding in http transfers to - #7712
Conversation
| this->result.data.append(data); | ||
| }) | ||
| { | ||
| requestHeaders = curl_slist_append(requestHeaders, "Accept-Encoding: zstd, br, gzip, deflate"); |
There was a problem hiding this comment.
We can't easily get this list from curl or at compile time?
There was a problem hiding this comment.
@SuperSandro2000 this is actually not curl decompressing but nix has its own decompression sinks below. In fact my first version was just doing curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, ""); (see docs) and disable having nix doing the decompression afterwards (or else it would break). I choose this way because it made the diff smaller and therefore more likely to be merged as nix reviewers are usually quite busy.
There was a problem hiding this comment.
Except from brotli, the decompression is transparently handled by libarchive IIRC. So ideally we could just query libarchive for that, but after a quick search I couldn't find a way to do that.
There was a problem hiding this comment.
@thufschmitt the alternative would be to let curl handle all of the decompression. Just make a call which way do you prefer.
There was a problem hiding this comment.
Dunno, I have hardly ever touched these parts of the codebase, and I've no idea why things are this way 🤷♂️ I guess @edolstra would have a more informed opinion here.
What would be the cost of letting curl handle it? Should it just be a matter of setting CURLOPT_ACCEPT_ENCODING or is there something more involved?
There was a problem hiding this comment.
From what I remember, curl doesn't support all the formats that Nix supports (e.g. bzip2 and xz, and I think the curl in nixpkgs didn't have brotli enabled at the time). And Nix has to have its own support for these formats anyway. So there isn't much advantage to letting curl handle the decompression.
There was a problem hiding this comment.
I think the curl in nixpkgs didn't have brotli enabled at the time
I changed that a good while ago and moved brotili support from curlFull to curl.
So we can just keep this as is and maybe need to update the values manual in the future due to the lack of better options?
They must only send what is written in Accept-Encoding. Thats why in addition to zstd supporting at least brotli and usually gzip, too is necessary for a normal webserver. Most browsers don't have adopted zstd yet or only behind a flag. Not that relevant for us here since nix support brotli for a while. |
|
My earlier attempt at this: #6694 |
thufschmitt
left a comment
There was a problem hiding this comment.
both variants are implemented and you just need to merge the one that you prefer. I think both are fine.
I actually think we can just merge that one since it's just a one-liner change and then think whether we want the full-curl approach.
So modulo a small suggestion, I think this is good to go
tl;dr: With this 1 line change I was able to get a speedup of 1.5x on 1Gbit/s wan connections by enabling zstd compression in nginx. Also nix already supported all common compression format for http transfer, webservers usually only enable them if they are advertised through the Accept-Encoding header. This pull requests makes nix advertises content compression support for zstd, br, gzip and deflate. It's particular useful to add transparent compression for binary caches that serve packages from the host nix store in particular nix-serve, nix-serve-ng and harmonia. I tried so far gzip, brotli and zstd, whereas only zstd was able to bring me performance improvements for 1Gbit/s WAN connections. The following nginx configuration was used in combination with the [zstd module](https://github.com/tokers/zstd-nginx-module) and [harmonia](https://github.com/nix-community/harmonia/) ```nix { services.nginx.virtualHosts."cache.yourhost.com" = { locations."/".extraConfig = '' proxy_pass http://127.0.0.1:5000; proxy_set_header Host $host; proxy_redirect http:// https://; proxy_http_version 1.1; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; zstd on; zstd_types application/x-nix-archive; ''; }; } ``` For testing I unpacked a linux kernel tarball to the nix store using this command `nix-prefetch-url --unpack https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.1.8.tar.gz`. Before: ```console $ nix build && rm -rf /tmp/hello && time ./result/bin/nix copy --no-check-sigs --from https://cache.thalheim.io --to 'file:///tmp/hello?compression=none' '/nix/store/j42mahch5f0jvfmayhzwbb88sw36fvah-linux-6.1.8.tar.gz' warning: Git tree '/scratch/joerg/nix' is dirty real 0m18,375s user 0m2,889s sys 0m1,558s ``` After: ```console $ nix build && rm -rf /tmp/hello && time ./result/bin/nix copy --no-check-sigs --from https://cache.thalheim.io --to 'file:///tmp/hello?compression=none' '/nix/store/j42mahch5f0jvfmayhzwb b88sw36fvah-linux-6.1.8.tar.gz' real 0m11,884s user 0m4,130s sys 0m1,439s ``` Signed-off-by: Jörg Thalheim <[email protected]> Update src/libstore/filetransfer.cc Co-authored-by: Théophane Hufschmitt <[email protected]>
cd27148 to
f20d372
Compare
|
Squashed. |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
tl;dr: With this 1 line change I was able to get a speedup of 1.5x on 1Gbit/s wan connections by enabling zstd compression in nginx.
Also nix already supported all common compression format for http transfer, webservers usually only enable them if they are advertised through the Accept-Encoding header.
This pull requests makes nix advertises content compression support for zstd, br, gzip and deflate.
It's particular useful to add transparent compression for binary caches that serve packages from the host nix store in particular nix-serve, nix-serve-ng and harmonia.
I tried so far gzip, brotli and zstd, whereas only zstd was able to bring me performance improvements for 1Gbit/s WAN connections.
The following nginx configuration was used in combination with the zstd module and harmonia
For testing I unpacked a linux kernel tarball to the nix store using this command
nix-prefetch-url --unpack https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.1.8.tar.gz.Before:
After:
Signed-off-by: Jörg Thalheim [email protected]
Motivation
Context
Checklist for maintainers
Maintainers: tick if completed or explain if not relevant
tests/**.shsrc/*/teststests/nixos/*