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 of time elapses, the system resumes the calls to the dependent downstream application. This topic describes how to create a circuit breaking rule and provides sample circuit breaking 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 throttling, you can perform circuit breaking on unstable methods or dependent downstream applications in traces to implement traffic protection. Due to the complexity of call relationships, if an error occurs in a specific stage of a trace during a request, the request fails, or the error may even cause the entire trace to be unavailable. If a method in a trace is unstable, for example, if the requests to the method time out or the ratio of abnormal requests increases, you can use the circuit breaking feature to restrict the requests to the method. This makes the requests fail in a short period of time 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.
Procedure
Log on to the MSE console, and select a region in the top navigation bar.
In the left-side navigation pane, choose
.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 WEB service tab of 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. On the page that appears, click the Flow protection tab. On the Flow protection tab, click the Fuse rule tab. On the Fuse rule tab, 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.
Parameters
The following table describes the parameters in the Add Circuit Breaking Rule dialog box.
Parameter | Description |
Interface name | The name of the interface to which you want to apply 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 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 (%).
|
Fusing duration (s) | The period in which circuit breaking is implemented. If circuit breaking is implemented on the resources, the calls to all the resources fail in the specified circuit breaking period. |
Fuse recovery strategy | Specifies whether a circuit breaker retriggers circuit breaking after the circuit breaking period elapses. Valid values:
|
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 | Specify the name of the interface to which you want to apply the circuit breaking rule. |
Statistical window duration | 1 | Set this parameter to 1. Unit: seconds. |
Minimum number of requests | 10 | Set this parameter to 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. |
Fusing duration (s) | 10 | Set this parameter to 10 seconds. |
Fuse recovery strategy | 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 | Specify the name of the interface to which you want to apply the circuit breaking rule. |
Statistical window duration | 1 | Set this parameter to 1. Unit: seconds. |
Minimum number of requests | 10 | Set this parameter to 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. |
Fusing duration (s) | 10 | Set this parameter to 10 seconds. |
Fuse recovery strategy | 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.