×
Community Blog Configure Sidecar Parameters to Balance gRPC/HTTP2 Streaming Performance and Resource Usage

Configure Sidecar Parameters to Balance gRPC/HTTP2 Streaming Performance and Resource Usage

This article outlines the parameters that Sidecars employ to control the performance of gRPC streaming and their mechanisms.

By Zehuan Shi

When an application utilizes gRPC for streaming data, it goes through Sidecars for forwarding. Sidecars operate at Layer 7, allowing them to parse the metadata of gRPC messages before forwarding them. In certain scenarios, such as establishing a large-scale stream over a single connection, Sidecars may consume more memory. This article outlines the parameters that Sidecars employ to control the performance of gRPC streaming and their mechanisms. Users can adjust these parameters to achieve a balance between Sidecar's performance and resource consumption.

Parameters Configured by Sidecars to Control gRPC

Sidecars offer the following parameters for gRPC streaming. Users can adjust these parameters to strike a balance between Sidecar's performance and resource usage.

Parameter Description Valid value 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 during the gRPC streaming. If you set this parameter to a small value on the upstream host, the memory usage at both endpoints is reduced.
Reference 1: HTTP/2 Flow-Control Windows Size.
Reference 2: The Envoy Documentation
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 during the gRPC streaming. If you set this parameter to a small value on the upstream host, the memory usage at both endpoints is reduced.
Reference 1: HTTP/2 Flow-Control Windows Size.
Reference 2: The Envoy Documentation
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, idle streams are terminated faster, therefore releasing the space occupied by related contexts and buffers. N/A 300s

Adjust Sidecar Configurations

To configure the mentioned parameters for a sidecar, you can utilize a custom EnvoyFilter template. Follow the steps below:

1. Use Templates to Write EnvoyFilter

This article provides three templates for adjusting upstream connections, downstream connections, and upstream and downstream connections. Simply replace the ${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}

2. Create a Custom EnvoyFilter Template

Log on to the ASM console and go to the Service Mesh details page. In the navigation pane, click Plug-in Marketplace. Search for Custom. Find the custom Envoy filter template and click Apply the Template.

1

Enter the name, h2-control, (the name can be customized), click Add an EnvoyFilter template for a specific adapted istio version, and select the adapted version in the new project. Select the current version of the mesh instance.

2

Paste the Envoy filter YAML file that you created in the first step into the input box of the adapted version that you added. Click OK to save the file. The creation process is now complete. For more information, please refer to the documentation: https://www.alibabacloud.com/help/en/doc-detail/157263.html. Bind the workload to the desired workload that you wish to adjust.

0 1 0
Share on

You may also like

Comments