Repository navigation
perf: compress api responses in the bundled Caddy - #1908
Conversation
The api does not compress its responses. The default match list of encode omits application/x-msgpack, the type of the instrument records list. Mitigates #1714. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W53iUShuoPRdGy8vrks2nm
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
An alternative to this would be to add compression into the API endpoint in node. |
|
This pull request was closed because its body does not meet
Fix the body with |
|
This pull request was closed because its body does not meet
Fix the body with |
|
This pull request was closed because its body does not meet
Fix the body with |
A deployment that uses the bundled Caddy now sends API responses compressed (zstd or gzip). Before, the API and the bundled Caddy sent all responses at full size. This is a mitigation for #1714, not its fix: on an instance with 19,099 records the dashboard's record list did not arrive in the web client's 10 s limit, and the dashboard showed "Reconnecting…" continuously.
Changes
/api/*whoseContent-Typeisapplication/jsonorapplication/x-msgpack, when the client sendsAccept-Encoding. Other content types and the/storage/*and web routes are not changed.Decisions
matchis given, in place of a plainencode zstd gzip. The default match list ofencodedoes not includeapplication/x-msgpack, which is the type of the instrument records list (MsgpackInterceptor). A plainencodethus compresses the small responses and not the largest one. The cost is that a new response type on the API is not compressed until it is added to the list.@fastify/compress. The alternative also covers deployments that do not use the bundled Caddy, but it adds a dependency and uses the API's one event loop for the compression work.Risks
Caddyfiledoes not get this change until the operator updates the copy.Notes
Tested in
caddy:2.7-alpine(the image indocker-compose.yaml) with thisCaddyfileand a mockapiupstream that serves a 1.62 MB JSON body of 20,000 small records:Content-TypeAccept-Encodingapplication/x-msgpackzstd, gzipapplication/x-msgpackgzipapplication/x-msgpackidentityapplication/json; charset=utf-8zstd, gzipapplication/octet-streamzstd, gzipWith a plain
encode zstd gzipin the same image, theapplication/x-msgpackresponse stays at 1,617,780 bytes. The body in the test was JSON text with a msgpack label, so the ratio for real msgpack bodies will be lower. The effect on the instance in #1714 is not measured.Adversarial review
Reviewed at commit c715c2c. pnpm check: green. The three steps of
pnpm check(lint, unit tests with coverage, end-to-end tests) ran green in the CI joblint-and-teston this commit, not on a local machine.Findings
CLEAN
Attestation
I, Claude Fable 5.2, attest that the review block above reports the adversarial review as it ran on the commit named, with every finding it returned.
🤖 Generated with Claude Code
https://claude.ai/code/session_01W53iUShuoPRdGy8vrks2nm