当前位置: 首页 > 文档资料 > Sentinel 中文文档 >

Circuit Breaking

优质
小牛编辑
138浏览
2023-12-01

Introduction

Circuit breaking provides stability and prevents cascading failures in distributed systems.

chain

Note: This document is for Sentinel 1.8.0 or above.

Circuit breaker strategy

  • Slow Request Ratio: Circuit breaking by slow request ratio. We'll need to provide the "upper-bound response time", and requests whose RT exceeds the upper-bound RT will be recorded as a slow request.
  • Error Ratio: Circuit breaking by the error ratio (error count / total completed count).
  • Error Count: Circuit breaking by the number of exceptions.

Circuit breaker rules

For circuit breaking rules, you can refer to here.

Circuit breaker state change observer

EventObserverRegistry.getInstance().addStateChangeObserver("logging",
    (prevState, newState, rule, snapshotValue) -> {
        if (newState == State.OPEN) {
            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()));
        }
    });

Demo

SlowRatioCircuitBreakerDemo