Configure circuit breaking rules

更新时间:
复制 MD 格式

Circuit breaking rules in AHAS monitor the response time or error ratio of your application's internal methods or downstream dependencies. When a specified threshold is reached, the rule immediately trips, blocking calls to the unstable dependency. For a specified period, the system prevents calls to this resource, protecting your application and ensuring high availability. After this period, calls to the resource resume.

Prerequisites

You have connected your application to Application Protection in AHAS. For more information, see Connect an application.

Background

In addition to throttling, circuit breaking is a critical measure for handling unstable methods or downstream dependencies in a call chain. Due to the complexity of distributed systems, an error in one part of the call chain can cause the entire request to fail. This instability can even be amplified, leading to a complete service outage. The circuit breaking feature addresses this by restricting calls to an unstable method when it experiences issues, such as timeouts or a high error ratio. This allows requests to fail fast, preventing the error from affecting the entire call chain. For more information about circuit breaking, see the circuit breaker pattern.

Circuit breaking rules are typically used for degradation for weak dependencies. For more information, see Degradation for weak dependencies.

Procedure

  1. Log on to the AHAS console.

  2. In the upper-left corner of the AHAS console, select the region where your application is deployed.

  3. In the left-side navigation pane, choose Throttling > Application Protection.

  4. On the Application Protection page, on the application card tab, click the target application card.

  5. In the left-side navigation pane, click Application Overview. In the interface list at the bottom of the page, find the target interface and click Circuit Breaking in the Actions column.
  6. On the circuit breaking rule tab, configure the rule.
    Note The slow call ratio, statistic window duration, and minimum number of requests parameters require Java SDK v1.6.0 or later, or Java Agent v1.7.5 or later.

Use case 1: Slow call ratio

For example, you can break the circuit for a third-party service that has a slow response time to prevent it from affecting your current interface.

In the Add Circuit Breaking Rule or Add Rule dialog box, configure the parameters as shown in the following table.

ParameterExample valueDescription
interface nametestThe name of the interface.
statistic window duration1The statistic window is 1 second.
threshold typeSlow Call RatioSets the threshold type to slow call ratio.
Slow Call RT1000A request is considered a slow call if its response time (RT) exceeds 1000 ms.
degradation threshold80%The slow call ratio that triggers circuit breaking is 80%.
circuit breaking duration10The circuit remains open for 10 seconds.
minimum number of requests10The minimum number of requests required to trigger circuit breaking is 10.
circuit breaking recovery policyOne-time Probing RecoveryAfter the circuit breaking duration, the breaker enters a half-open state and allows one probe request. If the request is successful (it is not a slow call and has no errors), the circuit closes and resumes normal operation. Otherwise, the circuit trips again.

After this rule is enabled, if the number of requests within a 1-second statistic window is greater than 10 and the slow call ratio exceeds 80%, the circuit breaker trips. For the next 10 seconds, subsequent requests fail fast. After 10 seconds, the circuit breaker enters a probing recovery state and allows one probe request. If the response time of this request is less than 1000 ms, the circuit closes and resumes normal operation. If the response time is greater than 1000 ms, the circuit trips again.

Use case 2: Error ratio

For example, if a third-party content service returns frequent errors, you can configure a circuit breaking rule to improve the user experience.

In the Add Circuit Breaking Rule or Add Rule dialog box, configure the parameters as shown in the following table.

ParameterExample valueDescription
interface nametestThe name of the interface.
statistic window duration1The statistic window is 1 second.
threshold typeError RatioSets the threshold type to error ratio.
degradation threshold80%The error ratio that triggers circuit breaking is 80%.
circuit breaking duration10The circuit remains open for 10 seconds.
minimum number of requests10The minimum number of requests required to trigger circuit breaking is 10.
circuit breaking recovery policyOne-time Probing RecoveryAfter the circuit breaking duration, the breaker enters a half-open state and allows one probe request. If the request is successful (it is not a slow call and has no errors), the circuit closes and resumes normal operation. Otherwise, the circuit trips again.

After this rule is enabled, if the number of requests within a 1-second statistic window is greater than 10 and the error ratio exceeds 80%, the circuit breaker trips. For the next 10 seconds, subsequent requests fail fast. After 10 seconds, the circuit breaker enters a probing recovery state and allows one probe request. If this request completes without errors, the circuit closes and resumes normal operation. Otherwise, the circuit trips again.

Parameters

The following table describes the parameters in the Add Circuit Breaking Rule or Add Rule dialog box.

ParameterDescription
interface nameThe application resource to which the rule applies.
statistic window durationThe time window for collecting request metrics. Valid values range from 1 second to 120 minutes.
minimum number of requestsThe minimum number of requests within a statistic window required to trigger circuit breaking. If the number of requests is less than this value, the circuit breaker does not trip, even if the threshold is met.
threshold typeThe metric used to trigger circuit breaking. You can select Slow Call Ratio or Error Ratio.
  • If you select Slow Call Ratio, you must specify a Slow Call RT (response time). A request is counted as a slow call if its response time exceeds this value.

    In Degradation threshold, set the slow call ratio that triggers circuit breaking. After the rule is enabled, if the number of requests within a statistical time window is greater than the configured Minimum number of requests and the slow call ratio exceeds the threshold, requests are automatically circuit-broken for the next Circuit breaking duration. After the circuit breaking duration passes, the circuit breaker enters a probing recovery state. If the response time of the next request is less than the configured Slow Call RT, the circuit breaking ends. If the response time is greater than the configured Slow Call RT, the circuit is broken again.

  • If you select Error Ratio, you must specify the degradation threshold for the error ratio.

    After the rule is enabled, if the number of exceptions within a statistical window is greater than the minimum number of requests and the exception ratio is greater than the threshold, then subsequent requests are automatically blocked for the circuit breaking duration.

circuit breaking durationThe duration for which the circuit remains open after it trips. During this period, all requests to the resource fail fast.
circuit breaking recovery policyThe recovery strategy for the circuit breaker when it enters the half-open state.
  • One-time Probing Recovery: After the circuit breaking duration elapses, the circuit breaker allows a single probe request to pass through. If the request meets the expected criteria (it is not a slow call or an error), the circuit closes. Otherwise, the circuit re-enters the open state.
  • Gradual Recovery: You must set the number of recovery steps and the minimum number of passed requests per step.
    • After the circuit breaking duration elapses, the circuit breaker recovers gradually based on the specified number of recovery steps. In each step, if the number of passed requests reaches the minimum value, a check is performed. If the requests in a step do not exceed the threshold, the proportion of allowed requests is gradually increased until traffic is fully restored. If the metrics in any step exceed the threshold, the circuit re-enters the open state.
    • The percentage of allowed requests (P) is calculated as P = 100 / N, where N is the number of recovery steps. The percentage for the first step is P, the second step is 2 × P, and so on, until it reaches 100%.
    • For example, if the number of recovery steps is 3 and the minimum number of passed requests per step is 5, the three steps will allow 33%, 67%, and 100% of requests, respectively. When the number of requests in a step is 5 or more, a check is performed. If the metrics do not exceed the threshold, the process moves to the next recovery step until the service is fully restored.
    Note The Gradual Recovery strategy requires Java SDK v1.6.2 or later.