自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Istio實(shí)現(xiàn)非侵入壓縮,微服務(wù)之間如何實(shí)現(xiàn)壓縮

開(kāi)發(fā) 架構(gòu)
微服務(wù)相互通信時(shí),特別是用了rest協(xié)議,即用http協(xié)議通信,配置壓縮和解壓,可以有效加快數(shù)據(jù)傳輸速度,減少網(wǎng)路延遲

[[442125]]

1使用場(chǎng)景

1.1gateway網(wǎng)關(guān)

用戶瀏覽器訪問(wèn)網(wǎng)頁(yè)時(shí),在gateway網(wǎng)關(guān)配置壓縮,減少傳輸數(shù)據(jù),加快網(wǎng)頁(yè)打開(kāi)速度。

1.2mesh內(nèi)部

微服務(wù)相互通信時(shí),特別是用了rest協(xié)議,即用http協(xié)議通信,配置壓縮和解壓,可以有效加快數(shù)據(jù)傳輸速度,減少網(wǎng)路延遲

這個(gè)很有用,比如如果我們的rpc協(xié)議是http,啟用壓縮就可以提高傳輸效率。

2實(shí)操

2.1網(wǎng)關(guān)配置壓縮

2.1.1示例1

  1. cat << EOF > ef-ingressgateway-http-filter-compression.yaml  
  2. apiVersion: networking.istio.io/v1alpha3 
  3. kind: EnvoyFilter 
  4. metadata: 
  5.   namespace: istio-system 
  6.   name: apply-to 
  7. spec: 
  8.   workloadSelector: 
  9.     labels: 
  10.       istio: ingressgateway 
  11.   configPatches: 
  12.     - applyTo: HTTP_FILTER 
  13.       match: 
  14.         context: GATEWAY 
  15.         listener: 
  16.           filterChain: 
  17.             filter: 
  18.               name: envoy.filters.network.http_connection_manager 
  19.               subFilter: 
  20.                 name: envoy.filters.http.router 
  21.       patch: 
  22.         operation: INSERT_BEFORE 
  23.         value: 
  24.           name: envoy.filters.http.compressor 
  25.           typed_config: 
  26.             "@type": type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor 
  27.             response_direction_config: 
  28.               common_config: 
  29.                 min_content_length: 100 
  30.                 content_type: 
  31.                 - 'text/html' 
  32.             compressor_library: 
  33.               name: text_optimized 
  34.               typed_config: 
  35.                 "@type": type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip 
  36.                 memory_level: 3 
  37.                 window_bits: 10 
  38.                 compression_level: BEST_COMPRESSION 
  39.                 compression_strategy: DEFAULT_STRATEGY 
  40. EOF 
  41.  
  42. kubectl apply -f ef-ingressgateway-http-filter-compression.yaml  -n istio-system 

配置參數(shù)說(shuō)明:

作用在http_filter上,type_url是固定的。response_direction_config對(duì)響應(yīng)做配置,min_content_length最小啟用壓縮大小,content_type對(duì)哪些類型啟用壓縮。compressor_library壓縮庫(kù)配置,

window_bits:

窗口位大小,值從9到15,大的值會(huì)有更好的壓縮,但內(nèi)存消耗更大,默認(rèn)是12,將產(chǎn)生4096字節(jié)窗口

compression_level

壓縮級(jí)別,將影響壓縮速度和壓縮大小。BEST,高壓縮,高延遲;SPEED低壓縮,低延遲;DEFAULT優(yōu)化的壓縮,將介于BEST和SPEED之間。默認(rèn)沒(méi)設(shè)置是DEFAULT.

memory_level

內(nèi)存級(jí)別,從1到9,控制壓縮庫(kù)內(nèi)存的使用量,值越高內(nèi)存用的多,但是更快,壓縮結(jié)果更好。默認(rèn)值是5.

compression_strategy:

DEFAULT , FILTERED , HUFFMAN , RLE

content_type:

默認(rèn)值 “application/javascript”, “application/json”, “application/xhtml+xml”, “image/svg+xml”, “text/css”, “text/html”, “text/plain”, “text/xml”

沒(méi)啟用壓縮前:

傳輸大小是4.6k

啟用壓縮后:

content-encoding為gzip,說(shuō)明啟用了gzip壓縮

大小由4.6k降到了1.9k

2.1.2提高壓縮參數(shù)

  1. cat << EOF > ef-ingressgateway-http-filter-compression-2.yaml  
  2. apiVersion: networking.istio.io/v1alpha3 
  3. kind: EnvoyFilter 
  4. metadata: 
  5.   namespace: istio-system 
  6.   name: apply-to 
  7. spec: 
  8.   workloadSelector: 
  9.     labels: 
  10.       istio: ingressgateway 
  11.   configPatches: 
  12.     - applyTo: HTTP_FILTER 
  13.       match: 
  14.         context: GATEWAY 
  15.         listener: 
  16.           filterChain: 
  17.             filter: 
  18.               name: envoy.filters.network.http_connection_manager 
  19.               subFilter: 
  20.                 name: envoy.filters.http.router 
  21.       patch: 
  22.         operation: INSERT_BEFORE 
  23.         value: 
  24.           name: envoy.filters.http.compressor 
  25.           typed_config: 
  26.             "@type": type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor 
  27.             response_direction_config: 
  28.               common_config: 
  29.                 min_content_length: 100 
  30.                 content_type: 
  31.                 - 'text/html' 
  32.             compressor_library: 
  33.               name: text_optimized 
  34.               typed_config: 
  35.                 "@type": type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip 
  36.                 memory_level: 9 
  37.                 window_bits: 15 
  38.                 compression_level: BEST_COMPRESSION 
  39.                 compression_strategy: DEFAULT_STRATEGY 
  40. EOF 
  41.  
  42. kubectl apply -f ef-ingressgateway-http-filter-compression-2.yaml  -n istio-system 

提高參數(shù)后傳輸數(shù)據(jù)從1.9k下降到1.8k

2.1.3最快壓縮速度

  1. cat << EOF > ef-ingressgateway-http-filter-compression-3.yaml  
  2. apiVersion: networking.istio.io/v1alpha3 
  3. kind: EnvoyFilter 
  4. metadata: 
  5.   namespace: istio-system 
  6.   name: apply-to 
  7. spec: 
  8.   workloadSelector: 
  9.     labels: 
  10.       istio: ingressgateway 
  11.   configPatches: 
  12.     - applyTo: HTTP_FILTER 
  13.       match: 
  14.         context: GATEWAY 
  15.         listener: 
  16.           filterChain: 
  17.             filter: 
  18.               name: envoy.filters.network.http_connection_manager 
  19.               subFilter: 
  20.                 name: envoy.filters.http.router 
  21.       patch: 
  22.         operation: INSERT_BEFORE 
  23.         value: 
  24.           name: envoy.filters.http.compressor 
  25.           typed_config: 
  26.             "@type": type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor 
  27.             response_direction_config: 
  28.               common_config: 
  29.                 min_content_length: 100 
  30.                 content_type: 
  31.                 - 'text/html' 
  32.             compressor_library: 
  33.               name: text_optimized 
  34.               typed_config: 
  35.                 "@type": type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip 
  36.                 memory_level: 9 
  37.                 window_bits: 15 
  38.                 compression_level: BEST_SPEED 
  39.                 compression_strategy: DEFAULT_STRATEGY 
  40. EOF 
  41.  
  42. kubectl apply -f ef-ingressgateway-http-filter-compression-3.yaml  -n istio-system 

BEST_SPEED傳輸大小從1.8k提升到1.9k

2.1.4請(qǐng)求啟用壓縮

  1. cat << EOF > ef-ingressgateway-http-filter-compression-4.yaml  
  2. apiVersion: networking.istio.io/v1alpha3 
  3. kind: EnvoyFilter 
  4. metadata: 
  5.   namespace: istio-system 
  6.   name: apply-to 
  7. spec: 
  8.   workloadSelector: 
  9.     labels: 
  10.       istio: ingressgateway 
  11.   configPatches: 
  12.     - applyTo: HTTP_FILTER 
  13.       match: 
  14.         context: GATEWAY 
  15.         listener: 
  16.           filterChain: 
  17.             filter: 
  18.               name: envoy.filters.network.http_connection_manager 
  19.               subFilter: 
  20.                 name: envoy.filters.http.router 
  21.       patch: 
  22.         operation: INSERT_BEFORE 
  23.         value: 
  24.           name: envoy.filters.http.compressor 
  25.           typed_config: 
  26.             "@type": type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor 
  27.             response_direction_config: 
  28.               common_config: 
  29.                 min_content_length: 100 
  30.                 content_type: 
  31.                 - 'text/html' 
  32.             request_direction_config: 
  33.               common_config: 
  34.                 enabled: 
  35.                   default_value: true 
  36.                   runtime_key: request_compressor_enabled 
  37.             compressor_library: 
  38.               name: text_optimized 
  39.               typed_config: 
  40.                 "@type": type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip 
  41.                 memory_level: 9 
  42.                 window_bits: 15 
  43.                 compression_level: BEST_SPEED 
  44.                 compression_strategy: DEFAULT_STRATEGY 
  45. EOF 
  46.  
  47. kubectl apply -f ef-ingressgateway-http-filter-compression-4.yaml  -n istio-system 

request_direction_config配置請(qǐng)求壓縮

2.1.5禁用響應(yīng)壓縮,只用請(qǐng)求壓縮

  1. cat << EOF > ef-ingressgateway-http-filter-compression-5.yaml  
  2. apiVersion: networking.istio.io/v1alpha3 
  3. kind: EnvoyFilter 
  4. metadata: 
  5.   namespace: istio-system 
  6.   name: apply-to 
  7. spec: 
  8.   workloadSelector: 
  9.     labels: 
  10.       istio: ingressgateway 
  11.   configPatches: 
  12.     - applyTo: HTTP_FILTER 
  13.       match: 
  14.         context: GATEWAY 
  15.         listener: 
  16.           filterChain: 
  17.             filter: 
  18.               name: envoy.filters.network.http_connection_manager 
  19.               subFilter: 
  20.                 name: envoy.filters.http.router 
  21.       patch: 
  22.         operation: INSERT_BEFORE 
  23.         value: 
  24.           name: envoy.filters.http.compressor 
  25.           typed_config: 
  26.             "@type": type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor 
  27.             response_direction_config: 
  28.               common_config: 
  29.                 enabled: 
  30.                   default_value: false 
  31.                   runtime_key: response_compressor_enabled 
  32.                 min_content_length: 100 
  33.                 content_type: 
  34.                 - 'text/html' 
  35.             request_direction_config: 
  36.               common_config: 
  37.                 enabled: 
  38.                   default_value: true 
  39.                   runtime_key: request_compressor_enabled 
  40.             compressor_library: 
  41.               name: text_optimized 
  42.               typed_config: 
  43.                 "@type": type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip 
  44.                 memory_level: 9 
  45.                 window_bits: 15 
  46.                 compression_level: BEST_SPEED 
  47.                 compression_strategy: DEFAULT_STRATEGY 
  48. EOF 
  49.  
  50. kubectl apply -f ef-ingressgateway-http-filter-compression-5.yaml  -n istio-system 

2.2mesh內(nèi)部配置壓縮

reviews,ratings之間啟用壓縮

  1. cat << EOF > ef-ratings-http-filter-compression.yaml  
  2. apiVersion: networking.istio.io/v1alpha3 
  3. kind: EnvoyFilter 
  4. metadata: 
  5.   name: ratings 
  6. spec: 
  7.   workloadSelector: 
  8.     labels: 
  9.       app: ratings 
  10.   configPatches: 
  11.     - applyTo: HTTP_FILTER 
  12.       match: 
  13.         context: SIDECAR_INBOUND 
  14.         listener: 
  15.           filterChain: 
  16.             filter: 
  17.               name: envoy.filters.network.http_connection_manager 
  18.               subFilter: 
  19.                 name: envoy.filters.http.router 
  20.       patch: 
  21.         operation: INSERT_BEFORE 
  22.         value: 
  23.           name: envoy.filters.http.compressor 
  24.           typed_config: 
  25.             "@type": type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor 
  26.             response_direction_config: 
  27.               common_config: 
  28.                 enabled: 
  29.                   default_value: true 
  30.                   runtime_key: response_compressor_enabled 
  31.                 min_content_length: 10 
  32.                 content_type: 
  33.                 - 'application/json' 
  34.             request_direction_config: 
  35.               common_config: 
  36.                 enabled: 
  37.                   default_value: true 
  38.                   runtime_key: request_compressor_enabled 
  39.             compressor_library: 
  40.               name: text_optimized 
  41.               typed_config: 
  42.                 "@type": type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip 
  43.                 memory_level: 9 
  44.                 window_bits: 12 
  45.                 compression_level: BEST_SPEED 
  46.                 compression_strategy: DEFAULT_STRATEGY 
  47. EOF 
  48.  
  49. kubectl apply -f ef-ratings-http-filter-compression.yaml  -n istio 

raings啟用了壓縮

reviews啟用解壓縮

  1. cat << EOF > ef-reviews-http-filter-compression.yaml  
  2. apiVersion: networking.istio.io/v1alpha3 
  3. kind: EnvoyFilter 
  4. metadata: 
  5.   name: reviews 
  6. spec: 
  7.   workloadSelector: 
  8.     labels: 
  9.       app: reviews 
  10.   configPatches: 
  11.     - applyTo: HTTP_FILTER 
  12.       match: 
  13.         context: SIDECAR_OUTBOUND 
  14.         listener: 
  15.           filterChain: 
  16.             filter: 
  17.               name: envoy.filters.network.http_connection_manager 
  18.               subFilter: 
  19.                 name: envoy.filters.http.router 
  20.       patch: 
  21.         operation: INSERT_BEFORE 
  22.         value: 
  23.           name: envoy.filters.http.decompressor 
  24.           typed_config: 
  25.             "@type": type.googleapis.com/envoy.extensions.filters.http.decompressor.v3.Decompressor 
  26.             response_direction_config: 
  27.               common_config: 
  28.                 enabled: 
  29.                   default_value: true 
  30.                   runtime_key: response_decompressor_enabled 
  31.             request_direction_config: 
  32.               common_config: 
  33.                 enabled: 
  34.                   default_value: false 
  35.                   runtime_key: request_decompressor_enabled 
  36.             decompressor_library: 
  37.               name: text_optimized 
  38.               typed_config: 
  39.                 "@type": type.googleapis.com/envoy.extensions.compression.gzip.decompressor.v3.Gzip 
  40.                 chunk_size: 4096 
  41.                 window_bits: 15 
  42. EOF 
  43.  
  44. kubectl apply -f ef-reviews-http-filter-compression.yaml  -n istio 
  • window_bits

窗口位大小,值從9到15,解壓的窗口位大小需要大于等于壓縮的窗口位大小。默認(rèn)值是15

  • chunk_size

塊大小,用于輸出緩存,默認(rèn)值是4096

value must be inside range [4096, 65536]

本文轉(zhuǎn)載自微信公眾號(hào)「k8s實(shí)戰(zhàn)」,可以通過(guò)以下二維碼關(guān)注。轉(zhuǎn)載本文請(qǐng)聯(lián)系k8s實(shí)戰(zhàn)公眾號(hào)。

 

責(zé)任編輯:武曉燕 來(lái)源: k8s實(shí)戰(zhàn)
相關(guān)推薦

2021-07-27 06:51:53

Istio 微服務(wù)Service Mes

2023-11-09 09:48:16

數(shù)據(jù)壓縮微服務(wù)

2020-04-10 10:36:20

網(wǎng)絡(luò)通信框架

2020-05-07 09:45:16

前端JS圖片壓縮

2016-04-01 10:34:29

APK壓縮Android

2018-08-27 10:54:30

C++壓縮存儲(chǔ)

2024-03-18 08:48:52

Spring多端認(rèn)證微服務(wù)

2020-11-15 23:48:57

服務(wù)網(wǎng)格微服務(wù)網(wǎng)絡(luò)網(wǎng)絡(luò)技術(shù)

2020-04-29 16:24:55

開(kāi)發(fā)iOS技術(shù)

2011-12-30 11:14:41

Javazip

2024-06-20 08:09:24

2020-10-20 11:12:11

Nodejs

2022-01-13 09:54:58

微服務(wù) Istio 通信

2011-07-27 16:26:42

iPhone 解壓 gzip

2011-05-20 14:03:31

哈夫曼

2020-06-30 07:58:39

微服務(wù)Spring BootCloud

2023-11-27 07:29:05

2023-06-05 08:00:00

mTLSIstio安全

2025-03-14 07:55:29

2018-09-14 16:18:26

Linux壓縮文件應(yīng)用程序
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)