您现在的位置是:亿华云 > 域名
Istio实现非侵入压缩,微服务之间如何实现压缩
亿华云2025-10-09 01:35:09【域名】1人已围观
简介1使用场景1.1gateway网关用户浏览器访问网页时,在gateway网关配置压缩,减少传输数据,加快网页打开速度。1.2mesh内部微服务相互通信时,特别是用了rest协议,即用http协议通信,
1使用场景
1.1gateway网关
用户浏览器访问网页时,实实现在gateway网关配置压缩,现非减少传输数据,侵入加快网页打开速度。压缩压缩
1.2mesh内部
微服务相互通信时,微服务特别是间何用了rest协议,即用http协议通信,实实现配置压缩和解压,现非可以有效加快数据传输速度,侵入减少网路延迟
这个很有用,压缩压缩比如如果我们的微服务rpc协议是http,启用压缩就可以提高传输效率。间何
2实操
2.1网关配置压缩
2.1.1示例1
cat << EOF > ef-ingressgateway-http-filter-compression.yaml apiVersion: networking.istio.io/v1alpha3 kind: EnvoyFilter metadata: namespace: istio-system name: apply-to spec: workloadSelector: labels: istio: ingressgateway configPatches: - applyTo: HTTP_FILTER match: context: GATEWAY listener: filterChain: filter: name: envoy.filters.network.http_connection_manager subFilter: name: envoy.filters.http.router patch: operation: INSERT_BEFORE value: name: envoy.filters.http.compressor typed_config: "@type": type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor response_direction_config: common_config: min_content_length: 100 content_type: - text/html compressor_library: name: text_optimized typed_config: "@type": type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip memory_level: 3 window_bits: 10 compression_level: BEST_COMPRESSION compression_strategy: DEFAULT_STRATEGY EOF kubectl apply -f ef-ingressgateway-http-filter-compression.yaml -n istio-system配置参数说明:
作用在http_filter上,实实现type_url是现非固定的。response_direction_config对响应做配置,侵入min_content_length最小启用压缩大小,content_type对哪些类型启用压缩。compressor_library压缩库配置,网站模板
window_bits:
窗口位大小,值从9到15,大的值会有更好的压缩,但内存消耗更大,默认是12,将产生4096字节窗口
compression_level
压缩级别,将影响压缩速度和压缩大小。BEST,高压缩,高延迟;SPEED低压缩,低延迟;DEFAULT优化的压缩,将介于BEST和SPEED之间。默认没设置是DEFAULT.
memory_level
内存级别,从1到9,控制压缩库内存的使用量,值越高内存用的多,b2b供应网但是更快,压缩结果更好。默认值是5.
compression_strategy:
DEFAULT , FILTERED , HUFFMAN , RLE
content_type:
默认值 “application/javascript”, “application/json”, “application/xhtml+xml”, “image/svg+xml”, “text/css”, “text/html”, “text/plain”, “text/xml”
没启用压缩前:
传输大小是4.6k
启用压缩后:
content-encoding为gzip,说明启用了gzip压缩
大小由4.6k降到了1.9k
2.1.2提高压缩参数
cat << EOF > ef-ingressgateway-http-filter-compression-2.yaml apiVersion: networking.istio.io/v1alpha3 kind: EnvoyFilter metadata: namespace: istio-system name: apply-to spec: workloadSelector: labels: istio: ingressgateway configPatches: - applyTo: HTTP_FILTER match: context: GATEWAY listener: filterChain: filter: name: envoy.filters.network.http_connection_manager subFilter: name: envoy.filters.http.router patch: operation: INSERT_BEFORE value: name: envoy.filters.http.compressor typed_config: "@type": type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor response_direction_config: common_config: min_content_length: 100 content_type: - text/html compressor_library: name: text_optimized typed_config: "@type": type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip memory_level: 9 window_bits: 15 compression_level: BEST_COMPRESSION compression_strategy: DEFAULT_STRATEGY EOF kubectl apply -f ef-ingressgateway-http-filter-compression-2.yaml -n istio-system提高参数后传输数据从1.9k下降到1.8k
2.1.3最快压缩速度
cat << EOF > ef-ingressgateway-http-filter-compression-3.yaml apiVersion: networking.istio.io/v1alpha3 kind: EnvoyFilter metadata: namespace: istio-system name: apply-to spec: workloadSelector: labels: istio: ingressgateway configPatches: - applyTo: HTTP_FILTER match: context: GATEWAY listener: filterChain: filter: name: envoy.filters.network.http_connection_manager subFilter: name: envoy.filters.http.router patch: operation: INSERT_BEFORE value: name: envoy.filters.http.compressor typed_config: "@type": type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor response_direction_config: common_config: min_content_length: 100 content_type: - text/html compressor_library: name: text_optimized typed_config: "@type": type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip memory_level: 9 window_bits: 15 compression_level: BEST_SPEED compression_strategy: DEFAULT_STRATEGY EOF kubectl apply -f ef-ingressgateway-http-filter-compression-3.yaml -n istio-systemBEST_SPEED传输大小从1.8k提升到1.9k
2.1.4请求启用压缩
cat << EOF > ef-ingressgateway-http-filter-compression-4.yaml apiVersion: networking.istio.io/v1alpha3 kind: EnvoyFilter metadata: namespace: istio-system name: apply-to spec: workloadSelector: labels: istio: ingressgateway configPatches: - applyTo: HTTP_FILTER match: context: GATEWAY listener: filterChain: filter: name: envoy.filters.network.http_connection_manager subFilter: name: envoy.filters.http.router patch: operation: INSERT_BEFORE value: name: envoy.filters.http.compressor typed_config: "@type": type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor response_direction_config: common_config: min_content_length: 100 content_type: - text/html request_direction_config: common_config: enabled: default_value: true runtime_key: request_compressor_enabled compressor_library: name: text_optimized typed_config: "@type": type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip memory_level: 9 window_bits: 15 compression_level: BEST_SPEED compression_strategy: DEFAULT_STRATEGY EOF kubectl apply -f ef-ingressgateway-http-filter-compression-4.yaml -n istio-systemrequest_direction_config配置请求压缩
2.1.5禁用响应压缩,只用请求压缩
cat << EOF > ef-ingressgateway-http-filter-compression-5.yaml apiVersion: networking.istio.io/v1alpha3 kind: EnvoyFilter metadata: namespace: istio-system name: apply-to spec: workloadSelector: labels: istio: ingressgateway configPatches: - applyTo: HTTP_FILTER match: context: GATEWAY listener: filterChain: filter: name: envoy.filters.network.http_connection_manager subFilter: name: envoy.filters.http.router patch: operation: INSERT_BEFORE value: name: envoy.filters.http.compressor typed_config: "@type": type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor response_direction_config: common_config: enabled: default_value: false runtime_key: response_compressor_enabled min_content_length: 100 content_type: - text/html request_direction_config: common_config: enabled: default_value: true runtime_key: request_compressor_enabled compressor_library: name: text_optimized typed_config: "@type": type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip memory_level: 9 window_bits: 15 compression_level: BEST_SPEED compression_strategy: DEFAULT_STRATEGY EOF kubectl apply -f ef-ingressgateway-http-filter-compression-5.yaml -n istio-system2.2mesh内部配置压缩
reviews,ratings之间启用压缩
cat << EOF > ef-ratings-http-filter-compression.yaml apiVersion: networking.istio.io/v1alpha3 kind: EnvoyFilter metadata: name: ratings spec: workloadSelector: labels: app: ratings configPatches: - applyTo: HTTP_FILTER match: context: SIDECAR_INBOUND listener: filterChain: filter: name: envoy.filters.network.http_connection_manager subFilter: name: envoy.filters.http.router patch: operation: INSERT_BEFORE value: name: envoy.filters.http.compressor typed_config: "@type": type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor response_direction_config: common_config: enabled: default_value: true runtime_key: response_compressor_enabled min_content_length: 10 content_type: - application/json request_direction_config: common_config: enabled: default_value: true runtime_key: request_compressor_enabled compressor_library: name: text_optimized typed_config: "@type": type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip memory_level: 9 window_bits: 12 compression_level: BEST_SPEED compression_strategy: DEFAULT_STRATEGY EOF kubectl apply -f ef-ratings-http-filter-compression.yaml -n istioraings启用了压缩
reviews启用解压缩
cat << EOF > ef-reviews-http-filter-compression.yaml apiVersion: networking.istio.io/v1alpha3 kind: EnvoyFilter metadata: name: reviews spec: workloadSelector: labels: app: reviews configPatches: - applyTo: HTTP_FILTER match: context: SIDECAR_OUTBOUND listener: filterChain: filter: name: envoy.filters.network.http_connection_manager subFilter: name: envoy.filters.http.router patch: operation: INSERT_BEFORE value: name: envoy.filters.http.decompressor typed_config: "@type": type.googleapis.com/envoy.extensions.filters.http.decompressor.v3.Decompressor response_direction_config: common_config: enabled: default_value: true runtime_key: response_decompressor_enabled request_direction_config: common_config: enabled: default_value: false runtime_key: request_decompressor_enabled decompressor_library: name: text_optimized typed_config: "@type": type.googleapis.com/envoy.extensions.compression.gzip.decompressor.v3.Gzip chunk_size: 4096 window_bits: 15 EOF kubectl apply -f ef-reviews-http-filter-compression.yaml -n istio window_bits窗口位大小,值从9到15,解压的窗口位大小需要大于等于压缩的窗口位大小。默认值是15
chunk_size块大小,用于输出缓存,默认值是4096
value must be inside range [4096, 65536]
本文转载自微信公众号「k8s实战」,可以通过以下二维码关注。转载本文请联系k8s实战公众号。
很赞哦!(6715)
相关文章
- 付款完成后,您只需耐心等待,如果您注册成功,系统会提示您。这里需要注意的是,域名是一个即时产品,只有在最终付款成功时才能预订,注册成功后不能更改。
- 为什么使用C ++而不是C#编写Windows?
- OkHttp透明压缩,收获性能10倍,外加故障一枚
- 详解增强算术赋值:“-=”操作是怎么实现的?
- 以上的就是为大家介绍的关于域名的详解域名注册:域名注册0
- 低代码和无代码的主要区别是什么?
- C++ Core Check:安全编码准则更新
- 详解java中的缓冲流、转换流、序列化流
- 主流搜索引擎显示的相关搜索项越多,越能积极反映该域名的市场价值。同时,被评估域名的搜索引擎显示结果不佳可能是由于以下两个原因:
- 推动软件交付的24个关键能力
站长推荐
用户邮箱的静态密码可能已被钓鱼和同一密码泄露。在没有收到安全警报的情况下,用户在适当的时间内不能更改密码。在此期间,攻击者可以随意输入帐户。启用辅助身份验证后,如果攻击者无法获取移动电话动态密码,他将无法进行身份验证。这样,除非用户的电子邮件密码和手机同时被盗,否则攻击者很难破解用户的邮箱。
Python中的高阶概念属性:五个你应该搞明白的知识点
C语言 volatile 关键字在编译优化过程中有何作用
16个非常有用的CSS伪选择器,你千万不要错过了!
3.dns修改成功后,点击“域名解析”,按提示进行操作。解析格式一般如下:
给你的公众号添加一个智能机器人
要理解好的代码,你需要多多编写“不好”的代码
好用到飞起!微软复活超强Windows工具集