Configure throttling policies

更新时间:
复制 MD 格式

Throttling protects backend services from excessive requests and prevents cascading failures. Cloud-native API Gateway supports route-level throttling policies that cap request volume within a specified time window.

Configure a throttling policy

Important

The throttling threshold that you configure is a gateway-level throttling threshold. You can calculate the throttling threshold for a gateway node by using the following formula: Gateway-level throttling threshold/Number of nodes. If the calculated throttling threshold is a decimal value, the decimal value is rounded up to the nearest integer. For example, the queries per second (QPS) of a demo route is 1001. If your gateway has two nodes, the QPS limit for the demo route on each gateway node is 501.

  1. You can configure a throttling policy within or outside a Cloud-native API Gateway instance.

    External API

    1. Log on to the Cloud-native API Gateway console. In the navigation pane on the left, click API. In the top navigation bar, select a region.

    2. Click the target API. From the drop-down list, select the instance for which you want to configure throttling, or select All Instances. From the instance drop-down list in the top navigation bar, select the target instance.

    3. In the Routes, click the target route.

    Internal API

    1. Log on to the Cloud-native API Gateway console. In the navigation pane on the left, click Instance. In the top navigation bar, select a region.

    2. On the Instance page, click the ID of the target gateway instance. In the navigation pane on the left, click API, and then click the target API.

    3. In the Routes, click the target route.

  2. Click the Configure Policy tab, and then click Enable Policy/Plug-in in the Inbound Processing section.

  3. Add a throttling policy. Options include Traffic Control, Concurrency Control, and Circuit Breaking.

    Traffic Throttling

    Throttling rules monitor the QPS of a route and block traffic immediately when the threshold is reached, preventing backend service breakdowns due to traffic surges.

    Click the Traffic Control card. In the Add Policy:Traffic Control panel, configure the parameters and then click Add.

    Parameter

    Description

    Enable or Not

    Turn on this switch to enable the traffic control policy.

    Overall QPS Threshold

    The Overall QPS Threshold.

    Web Fallback Behavior

    Set Web Fallback Behavior to Return Specific Content or Redirect to Specified Page.

    If you set Web Fallback Behavior to Return Specific Content:

    HTTP Status Code

    The HTTP Status Code to return. The default value is 429.

    Type of Returned Content

    The Type of Returned Content of the response body. You can select Regular Text or JSON.

    HTTP Text

    The text to return.

    If you set Web Fallback Behavior to Redirect to Specified Page:

    Redirect URL

    The Redirect URL.

    Concurrency control

    Concurrency rules track the total number of requests being processed by the gateway and block traffic when the count reaches the specified threshold, protecting backend service availability during high-concurrency scenarios.

    Click the Concurrency Control card. In the Add Policy: Concurrency Control panel, configure the parameters and then click Add.

    Parameter

    Description

    Enable or Not

    Turn on this switch to enable the concurrency rule.

    Overall Concurrency Threshold

    The Overall Concurrency Threshold.

    Web Fallback Behavior

    Set the Web Fallback Behavior to Return Specific Content or Redirect to Specified Page.

    If you set Web Fallback Behavior to Return Specific Content:

    HTTP Status Code

    The HTTP Status Code to return. The default value is 429.

    Type of Returned Content

    The Type of Returned Content of the response body. You can select Regular Text or JSON.

    HTTP Text

    The response body to return.

    If you set Web Fallback Behavior to Redirect to Specified Page:

    Redirect URL

    The Redirect URL.

    Circuit breaking

    Circuit breaking rules trip when the response time (RT) or exception ratio on a route reaches a specified threshold. Once tripped, the gateway rejects all requests on that route for a configured duration to protect backend services, then resumes calls automatically.

    Click the Circuit Breaking card. In the Add Policy: Circuit Breaking panel, configure the parameters and then click Add.

    Parameter

    Description

    Enable or Not

    Turn on this switch to enable the circuit breaking rule.

    Statistical Window Duration

    The duration of the time window. Valid values: 1 second to 120 minutes.

    Minimum Number of Requests

    The minimum number of requests required to trigger circuit breaking. If the request count in the current time window is below this value, circuit breaking is not triggered even if the threshold condition is met.

    Threshold Type

    The metric used to trigger circuit breaking. You can select Slow Call Ratio (%) or Exception Ratio (%).

    1. If you select Slow Call Ratio (%), you must set a Slow Call RT, which is the maximum response time. A request is considered a slow call if its response time is greater than this value. Once the rule is enabled, if the number of requests in a statistical window exceeds the minimum number of requests and the slow call ratio exceeds the specified threshold, requests are rejected for the circuit breaking duration. After the circuit breaking duration, the circuit breaker enters a probing recovery state. If the next request's response time is less than the specified Slow Call RT, the circuit closes. Otherwise, the circuit opens again.

    2. If you select Exception Ratio (%), you must set the exception ratio that triggers circuit breaking. Once the rule is enabled, if the number of business exceptions in a statistical window exceeds the minimum number of requests and the exception ratio exceeds the threshold, requests are rejected for the duration of the circuit breaking period.

    Slow Call RT

    The allowed Slow Call RT (maximum response time).

    Circuit Breaking Ratio Threshold

    The percentage threshold for slow calls. Circuit breaking is triggered when this threshold is reached or exceeded. Valid values: 0 to 100 (%).

    Circuit Breaking Duration (s)

    The duration for which circuit breaking stays active. During this period, all requests to the route are rejected.

    Web Fallback Behavior

    Select Web Fallback Behavior as Return Specific Content or Redirect to Specified Page.

    If you set Web Fallback Behavior to Return Specific Content:

    HTTP Status Code

    The HTTP Status Code to return. The default value is 429.

    Type of Returned Content

    The Type of Returned Content of the response body. You can select Regular Text or JSON.

    HTTP Text

    The response body to return.

    If you set Web Fallback Behavior to Redirect to Specified Page:

    Redirect URL

    The Redirect URL.

Verify results

Run the following command to send test requests:

curl -I http://121.196.XX.XX/demo/item/list     //The ingress IP address of the gateway.
  • A response similar to the following is returned if the throttling policy is not enabled:

    HTTP/1.1 200 OK
    x-content-type-options: nosniff
    x-xss-protection: 1; mode=block
    cache-control: no-cache, no-store, max-age=0, must-revalidate
    pragma: no-cache
    expires: 0
    x-frame-options: DENY
    content-type: application/json
    content-length: 86
    date: Mon, 29 Nov 2021 08:28:00 GMT
    x-envoy-upstream-service-time: 4
    server: istio-envoy
  • If the throttling policy is enabled, a response similar to the following is returned with HTTP status code 429.

    HTTP/1.1 429 Too Many Requests
    x-local-rate-limit: true
    content-length: 18
    content-type: text/plain
    date: Mon, 29 Nov 2021 08:28:01 GMT
    server: istio-envoy