In Microservices Engine (MSE), you can use circuit breaking rules to monitor the response time of requests or ratio of abnormal requests for an application or a downstream application on which the application depends. If the specified threshold is reached, MSE immediately lowers the priority of the dependent downstream application. The system does not call the abnormal downstream application within the specified period of time. This ensures stability and high availability of your application. After the specified period elapses, the system resumes calls to the dependent downstream application. This topic describes how to create a circuit breaking rule and provides sample rules for common scenarios.
Prerequisites
Microservices Engine (MSE) Enterprise Edition is activated.
The Microservices Governance feature of MSE is enabled for your microservices applications. For more information, see the following topics:
Background information
In addition to traffic control, circuit breaking for unstable methods or downstream dependencies in a call trace is also a key measure for traffic protection. Due to the complexity of call relationships, if an error occurs in any part of the call trace, the request fails. This can even amplify the instability and cause the entire trace to become unavailable. When a method in the call trace becomes unstable (for example, when the method times out or its ratio of abnormal requests increases), the circuit breaking feature restricts calls to that method. This allows the request to fail fast and prevents the error from affecting the entire trace.
In most cases, circuit breaking rules are applied to scenarios in which you need to lower the priority of a weakly dependent application.
For more information about sample circuit breaking rules, see the Scenario 1: Create a circuit breaking rule for slow calls and Scenario 2: Create a circuit breaking rule for abnormal requests sections of this topic.
Feature access
Log on to the MSE console, and select a region in the top navigation bar.
In the left-side navigation pane, choose Microservices Governance > Application Governance.
On the Application list page, find and click an application that you want to manage. On the details page of the application, create a circuit breaking rule by using one of the following methods:
In the left-side navigation pane, click API Details. On the page that appears, click the Client tab. Select an interface and click the Circuit Breaking tab. On the Circuit Breaking tab, click Added fusing rule.
In the left-side navigation pane, click Traffic management. Click the Flow protection tab, click Fuse rule, and then click Added fusing rule.
In the Add Circuit Breaking Rule dialog box, configure the rule parameters and click New.
For more information about the rule parameters, see the Parameters section of this topic.
Rule details
The following table describes the parameters in the Add Circuit Breaking Rule dialog box.
Parameter | Description |
Interface name | Application resources to which the rule applies. |
Statistical window duration | The length of the time window. The valid range is from 1 second to 120 minutes. |
Minimum number of requests | The minimum number of requests to trigger circuit breaking. If the number of requests in the current time window is less than the value of this parameter, circuit breaking is not triggered even if the circuit breaking rule is met. |
Threshold Type | The threshold type. Valid values: Slow call ratio (%) and Abnormal proportion (%).
|
Circuit Breaking Duration (s) | The period in which circuit breaking is implemented. If circuit breaking is implemented on the resources, all requests quickly fail in the configured duration. |
Circuit Breaking Policy | Recovery policy for the circuit breaker's recovery phase (half-open state).
|
Scenario 1: Create a circuit breaking rule for slow calls
For example, if you call a third-party service and the response time is long, the calls to the current interface are affected. To resolve this issue, you can perform circuit breaking on the slow calls.
In the Add Circuit Breaking Rule dialog box, configure the parameters that are described in the following table.
Parameter | Example | Description |
Interface name | test | Interface name. |
Statistical window duration | 1 | Set this parameter to 1. Unit: seconds. |
Minimum number of requests | 10 | The minimum number of requests to trigger the circuit breaker is 10. |
Threshold Type | Slow call ratio | Set this parameter to Slow call ratio (%). |
Slow call RT | 1000 | Set this parameter to 1000. Unit: milliseconds. If the response time of a request exceeds 1,000 milliseconds, the request is counted as a slow call. |
Circuit Breaking Ratio Threshold | 80% | Set this parameter to 80. Unit: %. If the percentage of slow calls reaches 80%, circuit breaking is triggered. |
Circuit Breaking Duration (s) | 10 | Set this parameter to 10 seconds. |
Circuit Breaking Policy | Single detection recovery | After the circuit breaking period elapses, the circuit breaker detects the next request. If the request is not a slow call or an abnormal request, circuit breaking ends. Otherwise, circuit breaking is triggered again. |
After the circuit breaking rule is enabled, if the number of requests is greater than 10 and the percentage of slow calls is greater than 80% within one second, all the requests fail within the next 10 seconds. After 10 seconds, the circuit breaker detects the next request. If the response time of the next request is less than 1,000 milliseconds, circuit breaking ends. Otherwise, circuit breaking is triggered again.
Scenario 2: Create a circuit breaking rule for abnormal requests
For example, when the content of a third-party service is displayed, abnormal requests occur in the system. If the ratio of abnormal requests is high, you can perform circuit breaking on the abnormal requests to ensure a better user experience.
In the Add Circuit Breaking Rule dialog box, configure the parameters that are described in the following table.
Parameter | Example | Description |
Interface name | test | API name. |
Statistical window duration | 1 | The statistics collection period is 1 second. |
Minimum number of requests | 10 | The minimum number of requests to trigger the circuit breaker is 10. |
Threshold Type | Abnormal proportion | Set this parameter to Abnormal proportion (%). |
Circuit Breaking Ratio Threshold | 80% | Set this parameter to 80. Unit: %. If the percentage of abnormal requests reaches 80%, circuit breaking is triggered. |
Circuit Breaking Duration (s) | 10 | Set this parameter to 10 seconds. |
Circuit Breaking Policy | Single detection recovery | After the circuit breaking period elapses, the circuit breaker detects the next request. If the request is not a slow call or an abnormal request, circuit breaking ends. Otherwise, circuit breaking is triggered again. |
After the circuit breaking rule is enabled, if the number of requests is greater than 10 and the percentage of abnormal requests is greater than 80% within one second, all the requests fail within the next 10 seconds. After 10 seconds, the circuit breaker detects the next request. If the next request is normal, circuit breaking ends. Otherwise, circuit breaking is triggered again.