cloudflare / pingora

A library for building fast, reliable and evolvable network services.
Apache License 2.0
20.25k stars 1.1k forks source link

Allow setting compression level per algorithm #228

Closed palant closed 1 week ago

palant commented 1 month ago

What is the problem your feature solves, or the need it fulfills?

Compression level can currently be set as following:

session.downstream_compression.adjust_level(9);

This calls ResponseCompressionCtx.adjust_level(). However, with gzip, brotli and zstd there are currently three compression algorithms supported, in future possibly more. The given compression level applies to all of them. And compression level 9 for gzip is radically different from compression level 9 for zstd.

Describe the solution you'd like

This API needs per-algorithm compression levels. So maybe adjust_level_gzip(9) and adjust_level_zstd(18), or some method taking an algorithm identifier along with a compression level. If necessary, method adjust_level() can be kept around for backwards compatibility and will still set the compression level for all algorithms.

Describe alternatives you've considered

It’s possible to set the compression level to 3 or 4 – these levels just so happen to provide a good tradeoff between size and speed for all of the supported algorithms. But that’s merely a coincidence.