-
Notifications
You must be signed in to change notification settings - Fork 127
Description
Hi!
We at @wongnai have forked gziphandler internally to add swappable gzip implementation. In production, we swap compress/gzip with our fork of yasushi-saito/cloudflare-zlib which result in 43% less CPU percentage used in the middleware.
We haven't open sourced anything in this project yet, as they require extensive modification to all projects to make it work. I'd like to check with upstream first whether this is something you'll be willing to merge before starting to work on open sourcing it (eg. unfork the go module name).
The changes we made are:
- Split
gzipWriterPools, poolIndex, addLevelPooland their tests into another submodule - Add an interface for gzip implementation:
type GzipWriter interface {
Close() error
Flush() error
Write(p []byte) (int, error)
}- The interface doesn't directly pool the underlying GzipWriter. The pooling is expected to be transparently done by the implementor of the interface. In the existing gzip implementation, the returned
gzip.Writeris wrapped in a struct that when closed, also return the writer to the pool. - Implementations are swapped by build tag. The default build still use compress/gzip to avoid extra non-Go dependency.
For forked cloudflare-zlib and its integration with gziphandler we may open source it later after the PR made here is merged. We removed its built-in zlib code and just simply link with installed library.