Modern microservice architectures are distributed and consist of a very large number of services. Different services call each other and form a complex call link. The above problems can have a magnified effect in link calls. If a link in a complex link is unstable, it may cascade to make the whole link unavailable. Therefore, we need to fuse down unstable weak dependent service calls to temporarily cut off unstable calls to avoid local unstable factors causing an avalanche of the whole. Fuse downgrading is usually configured on the client side (calling side) as a means of protecting itself.

Circuit breaker Strategies Sentinel provides the following circuit breaker strategies:

SLOW_REQUEST_RATIO: Select SLOW_REQUEST_RATIO as the threshold. You need to set RT (maximum response time) for slow calls. If the response time of a request is greater than this value, the request is counted as slow calls. If the number of requests in statIntervalMs is greater than the minimum number of requests and the ratio of delayed calls is greater than the threshold, the requests will be fused automatically in the following fuse duration. After the fuse duration, the fuse will enter the probe recovery state (half-open state). If the response time of the next request is less than the set slow-call RT, the fuse will end. If the response time is longer than the set slow-call RT, the fuse will be disconnected again.

ERROR_RATIO: When the number of requests within statIntervalMs is greater than the minimum number of requests and the proportion of exceptions is greater than the threshold, the requests will be fused automatically within the following fusing period. After the fuse period, the fuse enters the probe half-open state, terminating the fuse if the next request completes successfully (without error), otherwise it will be fused again. The threshold range for the abnormal ratio is [0.0, 1.0], representing 0-100%.

Number of exceptions (ERROR_COUNT) : When the number of exceptions in a unit statistics period exceeds the threshold, the circuit breaker is automatically disabled. After the fuse period, the fuse enters the probe half-open state, terminating the fuse if the next request completes successfully (without error), otherwise it will be fused again. Notice Exception degradation only applies to service exceptions. The exception (BlockException) of Sentinel traffic limiting degradation does not take effect. To count the proportion or number of exceptions, record service exceptions through tracer. trace(ex). Example:

Entry entry = null; try { entry = SphU.entry(key, EntryType.IN, key); // Write your biz code here. // <> } catch (Throwable t) { if (! BlockException.isBlockException(t)) {

Tracer.trace(t); } } finally { if (entry ! = www.pizei.comnull) {

entry.exit(); }} Open source integration modules such as Sentinel Dubbo Adapter, Sentinel Web Servlet Filter annotations automatically count business exceptions without manual invocation. A fuse DegradeRule provides the following important properties:

Field

instructions

The default value

resource

The resource name, which is the object of the rule

grade

Fuse breaker policy: supports the ratio of slow calls, ratio of exceptions, and number of exceptions policies

Slow call ratio

count

In slow call ratio mode, it is slow call critical RT (beyond this value, it is slow call); Anomaly ratio/anomaly number mode is the corresponding threshold value. If there is more intuitive understanding relative to electron, you can also refer to its official website:

www.pizei.com

timeWindow

Fusing duration, unit: s

minRequestAmount

The minimum number of requests triggered by fuses. If the number of requests is less than this value, fuses will not be triggered even if the abnormal ratio exceeds the threshold (introduced in 1.7.0)

5

statIntervalMs

Statistical duration (unit: ms), for example, 60*1000 represents minute level (introduced in 1.8.0)

1000 ms

slowRatioThreshold

Slow call ratio threshold, valid only for slow call ratio mode (introduced in 1.8.0)

Fuse event listener Sentinel supports the registration of custom event listeners to monitor fuse state change events. Example:

EventObserverRegistry.getInstance().addStateChangeObserver(“logging”,

(prevState, newState, rule, SnapshotValue) -> {if (newState == state.open) {// Conversion to OPEN State will carry the triggered value system.err.println (string.format (“%s -> OPEN at %d, snapshotValue=%.2f”, prevState.name(), TimeUtil.currentTimeMillis(), snapshotValue)); } else { System.err.println(String.format(“%s -> %s at %d”, prevState.name(), newState.name(), TimeUtil.currentTimeMillis())); }});