0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2025-01-06 22:40:31 -05:00

encode: Tweak compression settings (#4215)

* Tweak compression settings

zstd: Limit window sizes to 128K to keep memory in control both server and client size.
zstd: Write 0 length frames. This may be needed for compatibility.
zstd: Create fewer encoders. Small memory improvement.
gzip: Allow -2 (Huffman only) and -3 (stateless) compression modes.

* Update modules/caddyhttp/encode/zstd/zstd.go

Update docs.

Co-authored-by: Francis Lavoie <lavofr@gmail.com>

Co-authored-by: Francis Lavoie <lavofr@gmail.com>
This commit is contained in:
Klaus Post 2021-06-18 10:49:49 -07:00 committed by GitHub
parent 9d4ed3a323
commit 69c914483d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View file

@ -15,7 +15,6 @@
package caddygzip package caddygzip
import ( import (
"compress/flate"
"fmt" "fmt"
"strconv" "strconv"
@ -68,11 +67,11 @@ func (g *Gzip) Provision(ctx caddy.Context) error {
// Validate validates g's configuration. // Validate validates g's configuration.
func (g Gzip) Validate() error { func (g Gzip) Validate() error {
if g.Level < flate.NoCompression { if g.Level < gzip.StatelessCompression {
return fmt.Errorf("quality too low; must be >= %d", flate.NoCompression) return fmt.Errorf("quality too low; must be >= %d", gzip.StatelessCompression)
} }
if g.Level > flate.BestCompression { if g.Level > gzip.BestCompression {
return fmt.Errorf("quality too high; must be <= %d", flate.BestCompression) return fmt.Errorf("quality too high; must be <= %d", gzip.BestCompression)
} }
return nil return nil
} }

View file

@ -47,7 +47,10 @@ func (Zstd) AcceptEncoding() string { return "zstd" }
// NewEncoder returns a new gzip writer. // NewEncoder returns a new gzip writer.
func (z Zstd) NewEncoder() encode.Encoder { func (z Zstd) NewEncoder() encode.Encoder {
writer, _ := zstd.NewWriter(nil) // The default of 8MB for the window is
// too large for many clients, so we limit
// it to 128K to lighten their load.
writer, _ := zstd.NewWriter(nil, zstd.WithWindowSize(128<<10), zstd.WithEncoderConcurrency(1), zstd.WithZeroFrames(true))
return writer return writer
} }