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

  1. EventObserverRegistry.getInstance().addStateChangeObserver("logging",
  2. (prevState, newState, rule, snapshotValue) -> {
  3. if (newState == State.OPEN) {
  4. System.err.println(String.format("%s -> OPEN at %d, snapshotValue=%.2f", prevState.name(),
  5. TimeUtil.currentTimeMillis(), snapshotValue));
  6. } else {
  7. System.err.println(String.format("%s -> %s at %d", prevState.name(), newState.name(),
  8. TimeUtil.currentTimeMillis()));
  9. }
  10. });

Demo

SlowRatioCircuitBreakerDemo