Yoel-qin commented on issue #13927: URL: https://github.com/apache/apisix/issues/13927#issuecomment-6997122461
Picking this up. Target: browser clients, `Content-Encoding: zstd` for HTTP responses, same position as the gzip/brotli plugins. I have a working prototype (plugin mirroring `apisix/plugins/brotli.lua`, streaming via `ZSTD_compressStream2`) and will open the PR with tests and docs. Why a plugin instead of the nginx `http_zstd` module: no custom OpenResty build needed - same reason brotli is a plugin. Prototype numbers, standalone APISIX on apisix-runtime 1.4.2, 776,770-byte JSON payload (this repo's `admin-api.json` + `control-api.json`), sequential curl, 30 requests: | encoding | config | bytes | ratio | avg/p50 | |---|---|---|---|---| | identity | - | 776,770 | 1.0x | 2.7/2.6 ms | | gzip | level 6 | 62,510 | 12.4x | 10.0/9.8 ms | | brotli | level 6 | 46,696 | 16.6x | 19.0/18.8 ms | | zstd | level 3 (default) | 61,583 | 12.6x | 7.1/6.5 ms | | zstd | level 9 | 47,517 | 16.3x | 28.6/21.5 ms | | zstd | level 19 | 41,044 | 18.9x | 289.9/270.3 ms | Round-trip verified (sha256 identical to the original) for every row; requests without `Accept-Encoding` stay identity. At the default level 3, zstd matches gzip -6 on size with lower per-request cost; level 19 beats brotli -6 on ratio at a much higher CPU cost. Design follows brotli: q-value-aware `Accept-Encoding` parsing, skip when upstream already set `Content-Encoding` / `Content-Length < min_length` / type not matched, weak ETag downgrade, chunk-wise `ZSTD_e_flush` + `ZSTD_e_end` at eof. `comp_level` is capped at 19 so the window stays within the 8 MB decoders must support per RFC 9659. Proposed priority 994 (brotli 996, gzip 995, higher runs first). The libzstd FFI binding is small (~300 lines, `ZSTD_createCCtx`/`ZSTD_compressStream2` + decompressor for tests) since existing Lua zstd bindings are unmaintained (`luajit-zzip` last released 2019, repo idle since 2021; `lua-zstd` idle since ~2020). In the first PR I plan to vendor it next to the plugin (like the `jwt-auth` module layout); moving it to a standalone rock under the api7 org later is a one-line rockspec change. Only the system `libzstd` is needed (`apt install libzstd1` / `brew install zstd`). Default `comp_level` 3 and priority 994 are my current picks - shout if either should be different and I will adjust before the PR. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
