fix(fiber): use built-in compression middleware instead of manual gzip/deflate#222
fix(fiber): use built-in compression middleware instead of manual gzip/deflate#222
Conversation
…p/deflate Replace hand-rolled compress/flate and compress/gzip writers with Fiber's built-in compress middleware (github.com/gofiber/fiber/v2/middleware/compress). The middleware is applied globally with LevelBestSpeed. It handles Accept-Encoding negotiation, Content-Encoding headers, and compression automatically — the /compression handler just sends the raw payload and lets the framework decide whether to compress based on client headers. Other endpoints (baseline, json, etc.) won't be affected since wrk doesn't send Accept-Encoding by default. Fixes #221
|
@BennyFranciscus we dont use wrk, it's gcannon btw |
|
Oh right, my bad — gcannon, not wrk. Brain was on autopilot there 😅 I'll fix the PR description. Point still stands though — gcannon doesn't send |
|
The intended way by the framework, if it supports middleware for it, use it, if not then use the other approach |
|
Yeah exactly, that's what this PR does — Fiber has Anything else you want changed or is this good to go? |
|
/benchmark compression |
|
🚀 Benchmark run triggered for |
Benchmark ResultsFramework: Full log |
|
Nice — 13.6K req/s at 4096c, holds up well at 16384c too (11.6K). The middleware approach is performing solidly. Memory does climb a bit at high concurrency (10.6GiB at 16K connections) but that's expected with that many goroutines managing compressed buffers. Looks good to me. Happy with how this landed. |
Summary
Replaces the hand-rolled
compress/flateandcompress/gzipwriters in the/compressionhandler with Fiber's built-incompressmiddleware.What changed
Accept-Encodingparsing, manualContent-Encodingheader setting, directflate.NewWriter/gzip.NewWriterLevelcallscompress.New(compress.Config{Level: compress.LevelBestSpeed})applied globally viaapp.Use()/compressionhandler just sends the raw JSON payload. Fiber's middleware handles Accept-Encoding negotiation and compression transparently.Why
As flagged in #221, the previous implementation bypassed Fiber's documented compression API. The benchmark should measure how Fiber handles compression, not how Go's stdlib compressors perform behind Fiber's router.
Impact on other endpoints
None — gcannon doesn't send
Accept-Encodingheaders by default, so baseline, json, upload, db, etc. won't be compressed. Only the compression test (which explicitly sendsAccept-Encoding: gzip) will trigger compression.Fixes #221