Circuit Breaker

Circuit Breaker #

What is service fuse #

Summary #

When the server interface in the service is unstable and frequent timeouts or errors occur, it may cause an avalanche of service calls. We can turn on the service fusing function for applications, so that the faulty server can return errors in time, release system resources, and improve user experience and system performance.

Rules #

Fuses are set separately for services leading to each (standard. The number of records of fuse adjustment among multiple services is isolated from each other. The fuse monitors the execution status of the request and records:

  • Total requests
  • Number of errors
  • Success times
  • Consecutive success times
  • Number of consecutive failures

State #

Judge whether the adjustment is successful 4xx and 5xx according to the request response status code. The status code above 4xx is defined as failure. When the number of failures reaches the configured rules, the fuse will be triggered.

The fuse has three states

  • Closed state: when the fuse is in the closed state, the request can be released; When the failure times counted by the fuse trigger the switch, it turns to the open state.
  • Open status: when the fuse is open, all requests are not released, and failure is returned directly; Only after ⼀ set time window cycles, the fuse will switch to half open state.
  • Half open state: when the fuse is half open, only ⼀ requests can be released at present; After the put request obtains the response of the remote service, if it is successful, the fuse will switch to the closed state, otherwise it will switch to the open state.

Fuse Events #

image-20211019101817278

When the fusing rules are met, the fuse is opened to trigger fusing, and a fusing event will be generated at the same time. “Fusing event list” records all fusing, where you can view the specific details of fusing, including

  • Fusing time
  • Fuse service information, including current service and downstream abnormal service
  • Specific rules for triggering fuse, including:
  • The number of consecutive errors reached the threshold
  • Error rate reaches threshold
  • The number of consecutive errors or error rate reaches the threshold
  • The number of link errors and error rate reach the threshold

Next, the relevant contents of circuit breaker rules are described.

Fuse Rules #

Note that the service has default rules

In order to better protect the service and system stability, we configured the default fusing policy for the service. The rules are as follows: The number of consecutive errors reaches the threshold. The threshold number of errors is 5 times, the number of half open state requests is 1, the clearing cycle of closed state is 600 seconds, the half open trigger delay is 30 seconds, and the request timeout is 5 seconds.

If you need a looser fusing strategy, you need to configure it yourself, otherwise the default fusing rule will be adopted.

Rule List #

image-20211019101901100

The fusing rule list displays the fusing rule list configured by the platform. At the same time, you should also note that in order to ensure the stability of the service, we have set the default fusing rules for the service. As suggested above.

In order to better understand the fusing strategy, you can refer to “what is service fuse” at the beginning of the article.

Fuse Rule Configuration #

By clicking the “Add Fusing Rule” or “Edit” button, we can get the following configuration form:

image-20211019101928724

Here, you can configure the fuse rules in detail. Again, for better fuse configuration, you can refer to the relevant chapter of “what is service fuse” mentioned at the beginning of this article.

Some fuse parameter configurations are described as follows:

ParamDescription
maxRequestsThe number of requests allowed to operate when the fuse is half open is set to 1 by default. If the request is successful, the circuit breaker will be closed
IntervalThe clearing cycle when the fuse is closed. The default is 600s. If is closed, the requested times information will not be cleared
timeoutWhen the fuse is in the open state, how long will it be triggered to the half open state? The default is 30s, and then the state will be triggered if there is a request