Sentinel-thread isolation and circuit breaker degradation

1. Thread isolation

 ​​​​

 

Summarize

  • What are the two means of thread isolation?
    • Semaphore isolation
    • thread pool isolation
  • What are the characteristics of semaphore isolation?
    • Based on the counter mode, simple and low overhead
  • What are the characteristics of thread pool isolation?
    • Based on the thread pool mode, there is additional overhead, but the isolation control is stronger

2. Fuse downgrade

​How does Sentinel        Converged downgrading, it actually uses a circuit breaker to count an abnormal ratio and a slow request ratio when making a service call. If the abnormal ratio is too high when making a service call, and the threshold is triggered, the service will be fused and intercepted. All requests to access the service. In this way, the faulty service will be isolated, and it will not affect our normal service. (Just like in ancient times, the martial arts person, right? This hand was bitten by a poisonous snake, so he quickly raised his knife and dropped his hand, and the foot was poisoned. Ka, cut off the foot, to prevent the poison from spreading to the world. The whole body. So a strong man cutting off his wrist is a kind of self-protection). Of course, it's not a skill if you cut off your hand, it's a skill if you can bring it back. Therefore, service fusing is easy to do. If the service is restored in the future, access to the service should be restored. So how does our circuit breaker do it?

​ It is implemented by an internal state machine , which contains three states, namely Close, Open, and Half-Open. Open green means to go. In this state, the circuit breaker will not intercept any requests. No matter whether the request is normal or abnormal, it can be accessed. However, our circuit breaker will count the abnormal proportion of this call. If an abnormality is found during the statistical process If the ratio is too high and reaches the threshold, it will switch from the Closed state to the Open state, red means stop, then at this time it will intercept some requests entering the service, which is equivalent to a monopoly, but you can't always be Monopoly state (because in case the service is restored again), then our fusing state will have a duration. When the fusing time is over, it will switch from the Open state to the Half-Open state. In this state It will release a request, and then judge what to do next based on the result of this request. For example, Half-Open released a request, but found that the request still failed, then it will enter the Open state again and intercept all requests. , enter the fuse, of course, it lasts for a period of time, and then enters Half-Open, then if the request for release is completed and found to be successful, then it will switch from Half-Open to Cloesd. At this time, it is equal to Our logger has started to release again, so everyone can do whatever they want, and then start to do statistics again. Then these three states can be switched in this way. Therefore, we can not only fuse, but also restore, which is achieved by this. There are two key things here. The first is the duration of the fuse (this will definitely be configured by us in the future), and the second is the failure threshold, under what circumstances do you want to fuse. And this condition for achieving a circuit breaker is called a circuit breaker strategy in Sentinel.

 

circuit breaker strategy

What are the fuse strategies?

There are three types of circuit breaker fusing strategies: slow call, abnormal ratio, abnormal number

slow call

Slow call : A request whose service response time (RT) is longer than the specified time is considered a slow call request. Within the specified time, if the number of requests exceeds the set minimum number and the proportion of slow calls is greater than the set threshold, a circuit breaker will be triggered. For example:

Interpretation of the downgrade rule configuration above: calls with an RT exceeding 500ms are slow calls, and the last 10,000ms of requests are counted. If the number of requests exceeds 10, and the proportion of slow calls is not less than 0.5, a circuit breaker will be triggered, and the circuit breaker will last for 5 seconds. Then enter the half-open state and release a request for testing.

the case

 abnormal ratio, abnormal number

Summarize

What are the strategies for Sentinel circuit breaker downgrade?

  • Slow call ratio: Calls that exceed the specified duration are slow calls, and the ratio of slow calls within a unit of time is counted. If the threshold is exceeded, it will be blown

  • Abnormal ratio: the ratio of abnormal calls within the statistical unit duration, if the threshold is exceeded, the fuse will be disconnected

  • Abnormal number: Count the number of abnormal calls within the unit time, and if it exceeds the threshold, it will be blown

Guess you like

Origin blog.csdn.net/QRLYLETITBE/article/details/128957325