すべてのプロダクト
Search
ドキュメントセンター

Alibaba Cloud Service Mesh:ASMCompressor を使用してアプリケーションサービス間の呼び出しの圧縮構成を定義する

最終更新日:Nov 06, 2025

圧縮を実行する際、さまざまなプログラミング言語やフレームワークで異なる圧縮構成が使用されます。一貫した圧縮構成を使用する圧縮フィルターをアプリケーションに追加することで、圧縮構成の保守と管理を向上させることができます。圧縮構成には、最小圧縮バイト数、圧縮レベル、およびデフォルトで圧縮される応答が含まれます。このトピックでは、ASMCompressor を使用してアプリケーションサービス間の呼び出しの圧縮構成を定義する方法について説明します。

前提条件

機能の説明

ウェイポイントプロキシは Gzip と Brotli の両方のアルゴリズムをサポートしています。

  • Gzip は、多くの Web サーバーやブラウザでサポートされている広く使用されている圧縮アルゴリズムです。Gzip 圧縮アルゴリズムは、高い圧縮率と高速な圧縮速度で知られています。静的コンテンツと動的コンテンツの圧縮によく使用されます。

  • Brotli は、より高い圧縮率とより高速な展開速度を提供できる高度な圧縮アルゴリズムであり、Web サービスで広く使用されています。Brotli 圧縮アルゴリズムは、通常、HTML、カスケードスタイルシート (CSS)、JavaScript ファイルなどの静的コンテンツを圧縮するために使用されます。

Gzip と比較して、Brotli はより高い圧縮率を提供しますが、圧縮速度に影響を与える可能性があります。実際のアプリケーションシナリオとパフォーマンス要件に基づいて圧縮アルゴリズムを選択できます。

Gzip 圧縮の有効化と検証

ステップ 1: 圧縮が有効になっていない場合に返される応答のサイズを記録する

  1. イングレスゲートウェイの IP アドレスを取得します。

    1. ASM コンソールにログインします。左側のナビゲーションウィンドウで、[Service Mesh] > [メッシュ管理] を選択します。

    2. [メッシュ管理] ページで、ASM インスタンスの名前をクリックします。左側のナビゲーションウィンドウで、[ASM ゲートウェイ] > [イングレスゲートウェイ] を選択します。

    3. [イングレスゲートウェイ] ページで、[サービスアドレス] の値を取得します。

  2. ブラウザのアドレスバーに http://{ASM ゲートウェイアドレス}/productpage を入力して、Bookinfo アプリケーションにアクセスします。

  3. ブラウザで開発者モードをオンにし、productpage リクエストに対して返された応答のサイズを確認します。

    次の図に示すように、返された応答のサイズは 5.5 KB です。

    215BDB4C-576C-45ae-89ED-C378C13BB925.png

ステップ 2: Gzip 圧縮を有効にする

  1. 次の内容で ingressgateway-gzip.yaml ファイルを作成します。

    フィールドの詳細については、「ASMCompressor フィールドの説明」をご参照ください。

    ingressgateway-gzip.yaml を展開して表示

    apiVersion: istio.alibabacloud.com/v1beta1
    kind: ASMCompressor
    metadata:
      name: ingressgateway-gzip
      namespace: istio-system
    spec:
      compressor_library:
        gzip:
          compression_level: BEST_COMPRESSION
          compression_strategy: DEFAULT_STRATEGY
          memory_level: 9
          window_bits: 15
      isGateway: true
      portNumber: 80
      request_direction_config:  # リクエスト圧縮を無効にする
        common_config:
          enabled:
            default_value: false
            runtime_key: NOT_EXISTENT_KEY
      response_direction_config:  # 応答圧縮を有効にする
        common_config:
          content_type:
          - application/json
          - text/plain
          - text/html
          min_content_length: 100
        disable_on_etag_header: true
      workloadSelector:
        labels:
          istio: ingressgateway
  2. 次のコマンドを実行して Gzip 圧縮を有効にします:

    kubectl apply -f ingressgateway-gzip.yaml

ステップ 3: Gzip 圧縮が有効になった後の結果を表示する

  1. ブラウザのアドレスバーに http://{ASM ゲートウェイアドレス}/productpage を入力して、Bookinfo アプリケーションにアクセスします。

  2. ブラウザの開発者モードをオンにし、productpage リクエストに対して返された応答のサイズを確認します。

    次の図に示すように、返された応答のサイズが 5.5 KB から 1.8 KB に変更され、Gzip 圧縮構成が有効になったことを示しています。

    22.png

ステップ 4: Brotli 圧縮を検証する

  1. bookinfo という名前の仮想サービスを変更します。

    1. `bookinfo.yaml` ファイルの spec.http セクションに次の内容を追加します:

      - directResponse:
              body:
                string: >-
                  Hello, world! Hello, world! Hello, world! Hello, world! Hello,
                  world! Hello, world! Hello, world! Hello, world! Hello, world!
                  Hello, world!
                   Hello, world! Hello, world! Hello, world! Hello, world! Hello, world! Hello, world! Hello, world! Hello, world! Hello, world!
                    Hello, world! Hello, world! Hello, world! Hello, world!
              status: 200
            match:
              - uri:
                  prefix: /helloworld

      変更後の YAML ファイルの内容を次のコードに示します:

      変更された bookinfo.yaml ファイルを展開して表示

      apiVersion: networking.istio.io/v1beta1
      kind: VirtualService
      metadata:
        name: bookinfo
      spec:
        gateways:
          - bookinfo-gateway
        hosts:
          - '*'
        http:
          - directResponse:
              body:
                string: >-
                  Hello, world! Hello, world! Hello, world! Hello, world! Hello,
                  world! Hello, world! Hello, world! Hello, world! Hello, world!
                  Hello, world!
                   Hello, world! Hello, world! Hello, world! Hello, world! Hello, world! Hello, world! Hello, world! Hello, world! Hello, world!
                    Hello, world! Hello, world! Hello, world! Hello, world!
              status: 200
            match:
              - uri:
                  prefix: /helloworld
          - match:
              - uri:
                  exact: /productpage
              - uri:
                  prefix: /static
              - uri:
                  exact: /login
              - uri:
                  exact: /logout
              - uri:
                  prefix: /api/v1/products
            route:
              - destination:
                  host: productpage
                  port:
                    number: 9080
      
    2. 次のコマンドを実行して仮想サービスをデプロイします:

      kubectl apply -f bookinfo.yaml
  2. Brotli 圧縮を有効にします。

    1. 次の内容を使用して ingressgateway-brotli.yaml ファイルを作成します。

      フィールドの詳細については、「ASMCompressor フィールドの説明」をご参照ください。

      ingressgateway-brotli.yaml ファイルを展開して表示

      apiVersion: istio.alibabacloud.com/v1beta1
      kind: ASMCompressor
      metadata:
        name: ingressgateway-brotli
        namespace: istio-system
      spec:
        compressor_library:
          brotli:
            quality: 5
            window_bits: 15
        isGateway: true
        portNumber: 80
        request_direction_config:  # リクエスト圧縮を無効にする
          common_config:
            enabled:
              default_value: false
              runtime_key: NOT_EXISTENT_KEY
        response_direction_config:
          common_config:
            content_type:
            - application/json
            - text/plain
            - text/html
            min_content_length: 100
          disable_on_etag_header: true
        workloadSelector:
          labels:
            istio: ingressgateway
    2. 次のコマンドを実行して Brotli 圧縮を有効にします:

      kubectl apply -f ingressgateway-brotli.yaml
  3. Brotli 圧縮が有効になっているかどうかを確認します。

    1. 次のコマンドを実行して、/helloworld パスの応答を `out.br` ファイルに保存します:

      curl -I -H "Accept-Encoding: br" http://{IP address of the ASM gateway}/helloworld > out.br
    2. Brotli をインストールします。

      • macOS では、brew install brotli コマンドを実行して Brotli をインストールします。

      • Windows: インストール手順の詳細については、「brotli」をご参照ください。

    3. Brotli で次のコマンドを実行して out.br ファイルを展開します:

      brotli -d out.br

      展開されたファイルとその内容が表示され、Brotli 圧縮構成が有効になったことを示します。

ステップ 5: ルートレベルで構成を検証する

  1. ステップ 4 の設定を完了すると、すべてのパスからの応答に対して圧縮が有効になります。次のコマンドを使用して構成をテストします:

    curl ${IP address of the ASM gateway}/helloworld > helloworld_no_compress.html
    curl -H "Accept-Encoding: br" ${IP address of the ASM gateway}/helloworld > helloworld_compress.html
    curl ${IP address of the ASM gateway}/productpage > productpage_no_compress.html
    curl -H "Accept-Encoding: br" ${IP address of the ASM gateway}/productpage > productpage_compress.html
  2. ls コマンドを実行して、2 つのパスの応答サイズを比較します:

    ls -lh
    total 40
    -rw-r--r--@ 1 user  staff    37B  5 28 18:16 helloworld_compress.html
    -rw-r--r--@ 1 user  staff   324B  5 28 18:15 helloworld_no_compress.html
    -rw-r--r--@ 1 user  staff   1.2K  5 28 18:17 productpage_compress.html
    -rw-r--r--@ 1 user  staff   5.2K  5 28 18:16 productpage_no_compress.html
  3. 仮想サービスを変更して、`helloworld` パスに対応するルートにルート名を追加します。変更後の `bookinfo.yaml` ファイルは次のとおりです:

    変更された YAML ファイルを展開して表示

    apiVersion: networking.istio.io/v1beta1
    kind: VirtualService
    metadata:
      name: bookinfo
    spec:
      gateways:
        - bookinfo-gateway
      hosts:
        - '*'
      http:
        - directResponse:
            body:
              string: >-
                Hello, world! Hello, world! Hello, world! Hello, world! Hello,
                world! Hello, world! Hello, world! Hello, world! Hello, world!
                Hello, world!
                 Hello, world! Hello, world! Hello, world! Hello, world! Hello, world! Hello, world! Hello, world! Hello, world! Hello, world!
                  Hello, world! Hello, world! Hello, world! Hello, world!
            status: 200
          match:
            - uri:
                prefix: /helloworld
          name: helloworld-route    # ルートの名前を指定します。これにより、圧縮プラグインがパケットをより簡単に照合できるようになります。
        - match:
            - uri:
                exact: /productpage
            - uri:
                prefix: /static
            - uri:
                exact: /login
            - uri:
                exact: /logout
            - uri:
                prefix: /api/v1/products
          route:
            - destination:
                host: productpage
                port:
                  number: 9080
  4. ASMCompressor にルートレベルの構成を追加し、helloworld ルートで圧縮機能を無効にします。変更された ASMCompressor の内容を次のコードに示します:

    apiVersion: istio.alibabacloud.com/v1beta1
    kind: ASMCompressor
    metadata:
      name: ingressgateway-gzip
      namespace: istio-system
    spec:
      compressor_library:
        brotli:
          quality: 5
          window_bits: 15
      isGateway: true
      portNumber: 80
      request_direction_config:  # リクエスト圧縮を無効にします。
        common_config:
          enabled:
            default_value: false
            runtime_key: NOT_EXISTENT_KEY
      response_direction_config:
        common_config:
          content_type:
          - application/json
          - text/plain
          - text/html
          min_content_length: 100
        disable_on_etag_header: true
      per_route_configs:  # 新しいルートレベルの構成
      - disabled: true
        route_match:
          vhost:
            route:
              name: helloworld-route  # VirtualService で構成されたルート名を入力します。
      workloadSelector:
        labels:
          istio: ingressgateway
  5. 次のコマンドを実行して、/helloworld パスの応答圧縮が無効になっていることを確認します:

    curl -H "Accept-Encoding: br" ${IP address of the ASM gateway}/helloworld > helloworld_route_disabled.html
  6. ls コマンドを再度実行して、`/helloworld` パスの応答サイズを確認します。

    ls -lh
    total 48
    -rw-r--r--@ 1 user  staff    37B  5 28 18:16 helloworld_compress.html
    -rw-r--r--@ 1 user  staff   324B  5 28 18:15 helloworld_no_compress.html
    -rw-r--r--@ 1 user  staff   324B  5 28 19:29 helloworld_route_disabled.html
    -rw-r--r--@ 1 user  staff   1.3K  5 28 19:30 productpage_compress.html
    -rw-r--r--@ 1 user  staff   5.2K  5 28 18:16 productpage_no_compress.html

    出力は、ルートレベルで圧縮が無効になっていることを示しています。