All Products
Search
Document Center

Alibaba Cloud Service Mesh:Configure sidecar parameters to balance HTTP/2 streaming performance and resource usage

Last Updated:Jan 24, 2024

When an application uses HTTP/2 streaming, the sidecar parses and forwards message metadata based on Layer 7 protocols. In scenarios such as a large number of streams over a single connection, the memory usage of the sidecar may increase. This topic describes the parameters provided by sidecars to control the performance of HTTP/2 streaming. You can configure these parameters to adjust the resource usage of sidecar.

Parameter description

The following table describes the parameters provided by sidecars for HTTP/2 streaming. You can configure these parameters to balance the performance of HTTP/2 streaming and the resource usage of sidecars.

Parameter

Description

Valid range

Default value

http2_protocol_options.initial_connection_window_size

Specifies the initial connection flow-control window size of HTTP/2 streams on the sender. If you set this parameter to a small value on the upstream host, the memory usage at both endpoints is reduced. For more information, see Initial Flow-Control Window Size and Protocol Options.

65535~2147483647

65535

http2_protocol_options.initial_stream_window_size

Specifies the initial stream flow-control window size of HTTP/2 streams on the sender. If you set this parameter to a small value on the upstream host, the memory usage at both endpoints is reduced. For more information, see Initial Flow-Control Window Size and Protocol Options.

65535~2147483647

65535

http2_protocol_options.max_concurrent_streams

Specifies the maximum number of streams that can be created over a connection. If you set this parameter to a large value, the number of concurrent streams is increased and the transmission efficiency is improved, but the CPU and memory usage on both the sender and the receiver rises. If you set this parameter to a small value, the number of concurrent streams is reduced and the transmission efficiency is impaired, but the CPU and memory usage on both the sender and the receiver decreases.

1~2147483647

2147483647

stream_idle_timeout (valid for only downstream connections)

Specifies the maximum period of time a stream can remain inactive. If the stream continues to be inactive beyond this period of time, it will time out and be terminated. If you decrease the parameter value, idles streams are terminated faster, therefore releasing the space occupied by related contexts and buffers.

N/A

300s

Adjust sidecar configurations

To configure the preceding parameters of a sidecar, you need to use a custom Envoy filter template. Perform the following steps:

Step 1: Use templates to write EnvoyFilter

This topic provides three templates to adjust the parameter values for upstream connections, downstream connections, and upstream and downstream connections, respectively. Replace ${TO_BE_POPULATE} in the templates with your desired values.

  • Template used to adjust the parameter values for upstream connections:

    apiVersion: networking.istio.io/v1alpha3
    kind: EnvoyFilter
    metadata:
      name: h2-control
      namespace: default
    spec:
      configPatches:
      - applyTo: CLUSTER
        match:
          proxy:
            proxyVersion: ^1\.[1-9][0-9].*
        patch:
          operation: MERGE
          value:
            http2_protocol_options:
              initial_connection_window_size: ${TO_BE_POPULATE}
              initial_stream_window_size: ${TO_BE_POPULATE}
              max_concurrent_streams: ${TO_BE_POPULATE}
  • Template used to adjust parameter values for downstream connections:

    apiVersion: networking.istio.io/v1alpha3
    kind: EnvoyFilter
    metadata:
      name: h2-control
      namespace: default
    spec:
      configPatches:
      - applyTo: NETWORK_FILTER
        match:
          listener:
            filterChain:
              filter:
                name: envoy.filters.network.http_connection_manager
          proxy:
            proxyVersion: ^1\.[1-9][0-9].*
        patch:
          operation: MERGE
          value:
            typed_config:
              '@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
              http2_protocol_options:
                initial_connection_window_size: ${TO_BE_POPULATE}
                initial_stream_window_size: ${TO_BE_POPULATE}
                max_concurrent_streams: ${TO_BE_POPULATE}
              stream_idle_timeout: ${TO_BE_POPULATE}
  • Template used to adjust parameter values for upstream and downstream connections:

    apiVersion: networking.istio.io/v1alpha3
    kind: EnvoyFilter
    metadata:
      name: h2-control
      namespace: default
    spec:
      configPatches:
      - applyTo: CLUSTER
        match:
          proxy:
            proxyVersion: ^1\.[1-9][0-9].*
        patch:
          operation: MERGE
          value:
            http2_protocol_options:
              initial_connection_window_size: ${TO_BE_POPULATE}
              initial_stream_window_size: ${TO_BE_POPULATE}
              max_concurrent_streams: ${TO_BE_POPULATE}
      - applyTo: NETWORK_FILTER
        match:
          listener:
            filterChain:
              filter:
                name: envoy.filters.network.http_connection_manager
          proxy:
            proxyVersion: ^1\.[1-9][0-9].*
        patch:
          operation: MERGE
          value:
            typed_config:
              '@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
              http2_protocol_options:
                initial_connection_window_size: ${TO_BE_POPULATE}
                initial_stream_window_size: ${TO_BE_POPULATE}
                max_concurrent_streams: ${TO_BE_POPULATE}
              stream_idle_timeout: ${TO_BE_POPULATE}

Step 2: Create a custom EnvoyFilter template

  1. Log on to the ASM console.

  2. In the left-side navigation pane, choose Service Mesh > Mesh Management.

  3. On the Mesh Management page, find the ASM instance that you want to configure. Click the name of the ASM instance or click Manage in the Actions column.

  4. On the details page of the ASM instance, choose Plugin Extension Center > Market Place in the left-side navigation pane.

  5. On the EnvoyFilter Template page, click Create EnvoyFilter Template. On the page that appears, configure the parameters, and then click Create.

    Section

    Description

    Basic Information

    In this section, specify the name of the custom EnvoyFilter template. In this topic, the name is set to h2-control.

    Multi-version adapted EnvoyFilter templates

    Click Add an EnvoyFilter template for specific adapted istio version., select an Istio version, and copy the EnvoyFilter written in Step 1 to the YAML editor box.

  6. Bind the Envoy filter template to workloads and namespaces. For more information, see Manage Envoy filters.