Activate gzip compression on the Istio-proxy workload
Do you want to optimize your network bandwidth easy way?
Envoy compression filter helps us to improve this process.
Istio doesn't have any CRD to enable gzip compression. Alright at this point EnvoyFilter rescues us to enable gzip.
Gzip is an HTTP filter that enables Envoy to compress dispatched data from an upstream service upon client request. Compression is useful in situations where large payloads need to be transmitted without compromising the response time.
Before Istio 1.7
Enable gzip any workload or istio-ingress gw
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: application-gzip
namespace: istio-system
spec:
workloadSelector:
labels:
app: workload-app
configPatches:
- applyTo: HTTP_FILTER
match:
context: SIDECAR_INBOUND
listener:
filterChain:
filter:
name: "envoy.http_connection_manager"
subFilter:
name: 'envoy.router'
patch:
operation: INSERT_BEFORE
value:
name: envoy.gzip
config:
remove_accept_encoding_header: true
compression_level: DEFAULT
compression_strategy:
How it works
When gzip filter is enabled, request and response headers are inspected to determine whether or not the content should be compressed.
config.filter.http.gzip.v2.Gzip
memory_level: 1 to 9
Value from 1 to 9 that controls the amount of internal memory used by zlib.compression_level: DEFAULT|BEST|SPEED
A value used for selecting the zlib compression level.compression_strategy: DEFAULT|FILTERED|HUFFMAN|RLE
A value used for selecting the zlib compression strategy which is directly related to the characteristics of the content.
config.filter.http.compressor.v2.Compressor
content_length: Minimum response length, in bytes, which will trigger compressioncontent_type: Set of strings that allows specifying which mime-types yield compression
After Istio 1.7
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: application-gzip
namespace: istio-system
spec:
workloadSelector:
labels:
app: workload-app
configPatches:
- applyTo: HTTP_FILTER
match:
context: SIDECAR_INBOUND
listener:
filterChain:
filter:
name: envoy.http_connection_manager
subFilter:
name: envoy.router
patch:
operation: INSERT_BEFORE
value:
name: envoy.filters.http.compressor
typed_config:
'@type': type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor
compressor_library:
name: text_optimized
typed_config:
'@type': type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip
remove_accept_encoding_header: true
Statistics
Every configured Compressor filter has statistics rooted at <stat_prefix>.compressor.<compressor_library.name>.<compressor_library_stat_prefix>.<direction_prefix>.* with the following:
Result
Before enabled gzip compression our average response size 100kB. It’s really high for network bandwidth.
After we enabled gzip compression our response size dramatically reduce at this time. %2 CPU usage increased.