All Products
Search
Document Center

Microservices Engine:Create a circuit breaking rule

Last Updated:Sep 13, 2023

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

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

  1. Log on to the MSE console, and select a region in the top navigation bar.

  2. In the left-side navigation pane, choose Microservices Governance > Application Governance.

  3. 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.

  4. 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 (%).

  • If you set this parameter to Slow call ratio, you must set the Slow call RT parameter, which specifies a threshold for the response time of requests. If the response time of a request exceeds the value of the Slow call RT parameter, the request is counted as a slow call.

    You must also set the Circuit Breaking Ratio Threshold parameter, which specifies a percentage threshold that triggers circuit breaking for slow calls. After the circuit breaking rule is enabled, if the number of requests in the specified time window is greater than the value of the Minimum number of requests parameter and the percentage of slow calls is greater than the value of the Circuit Breaking Ratio Threshold parameter, requests are automatically blocked within the circuit breaking period that is specified by the Fusing duration (s) parameter. After the circuit breaking period elapses, the circuit breaker detects the next request. If the response time of the next request is less than the value of the Slow call RT parameter, circuit breaking ends. If the response time of the next request is greater than the value of the Slow call RT parameter, circuit breaking is triggered again.

  • If you set this parameter to Abnormal proportion, you must set the Circuit Breaking Ratio Threshold parameter, which specifies a percentage threshold that triggers circuit breaking for abnormal requests.

    After the circuit breaking rule is enabled, if the number of abnormal requests within the time window is greater than the value of the Minimum number of requests parameter and the percentage of abnormal requests is greater than the value of the Circuit Breaking Ration Threshold parameter, requests are automatically blocked within the circuit breaking period that is specified by the Fusing duration (s) parameter.

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:

  • 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.

  • Progressive recovery: If you select this option, you must set the Number of recovery phases and Minimum number of passes per step parameters.

    • After the circuit breaking period elapses, the circuit breaker performs progressive recovery based on the specified number of recovery stages. If the number of requests in a stage reaches the value of the Minimum number of passes per step parameter, a check is triggered. If the number of checked requests does not exceed the value of the Circuit Breaking Ratio Threshold parameter, the percentage of requests that are allowed to pass is gradually increased until all the requests are allowed to pass. If the number of checked requests exceeds the value of the Circuit Breaking Ratio Threshold parameter in a stage, circuit breaking is triggered again.

    • The request ratio is calculated based on the following formula: Request ratio (T) = 100/Number of recovery stages (N). The request ratio in the first stage is T and the request ratio in the second stage is 2T. The calculation ends until the request ratio is equal to 100%.

    • For example, if the number of recovery stages is 3 and the minimum number of requests that are allowed to pass in each stage is 5, requests are distributed in the three stages based on the ratios of 33%, 67%, and 100%. If the number of requests in each stage is greater than or equal to 5, a check is triggered. If the number of requests in each stage is less than 5, the system enters the next recovery stage until all the requests are allowed to pass.

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.