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
Log on to the AHAS console.
In the upper-left corner of the AHAS console, select the region where your application is deployed.
In the left-side navigation pane, choose .
On the Application Protection page, on the application card tab, click the target application card.
- 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.
- On the circuit breaking rule tab, configure the rule.Note The
slow call ratio,statistic window duration, andminimum number of requestsparameters 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.
| Parameter | Example value | Description |
| interface name | test | The name of the interface. |
| statistic window duration | 1 | The statistic window is 1 second. |
| threshold type | Slow Call Ratio | Sets the threshold type to slow call ratio. |
| Slow Call RT | 1000 | A request is considered a slow call if its response time (RT) exceeds 1000 ms. |
| degradation threshold | 80% | The slow call ratio that triggers circuit breaking is 80%. |
| circuit breaking duration | 10 | The circuit remains open for 10 seconds. |
| minimum number of requests | 10 | The minimum number of requests required to trigger circuit breaking is 10. |
| circuit breaking recovery policy | One-time Probing Recovery | After 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.
| Parameter | Example value | Description |
| interface name | test | The name of the interface. |
| statistic window duration | 1 | The statistic window is 1 second. |
| threshold type | Error Ratio | Sets the threshold type to error ratio. |
| degradation threshold | 80% | The error ratio that triggers circuit breaking is 80%. |
| circuit breaking duration | 10 | The circuit remains open for 10 seconds. |
| minimum number of requests | 10 | The minimum number of requests required to trigger circuit breaking is 10. |
| circuit breaking recovery policy | One-time Probing Recovery | After 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.
| Parameter | Description |
| interface name | The application resource to which the rule applies. |
| statistic window duration | The time window for collecting request metrics. Valid values range from 1 second to 120 minutes. |
| minimum number of requests | The 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 type | The metric used to trigger circuit breaking. You can select Slow Call Ratio or Error Ratio.
|
| circuit breaking duration | The duration for which the circuit remains open after it trips. During this period, all requests to the resource fail fast. |
| circuit breaking recovery policy | The recovery strategy for the circuit breaker when it enters the half-open state.
|