Documentation
¶
Index ¶
- Constants
- Variables
- type Breaker
- type CircuitBreaker
- func (b *CircuitBreaker) AdjustBreakers(count int, options Options)
- func (b *CircuitBreaker) GenBreaker(cmd int32, options Options) *Breaker
- func (b *CircuitBreaker) GetAllBreakers() map[int32]*Breaker
- func (b *CircuitBreaker) GetBreaker(cmd int32) *Breaker
- func (b *CircuitBreaker) IsTriggerBreaker(cmd int32) bool
- type Container
- type Options
- type State
- type StateChangeHandler
- type TripFunc
Constants ¶
View Source
const ( // COOLING_TIMEOUT is the time the breaker stay in OPEN before becoming HALFOPEN DEFAULT_COOLING_TIMEOUT = time.Second * 5 // DETECT_TIMEOUT is the time interval between every detect in HALFOPEN DEFAULT_DETECT_TIMEOUT = time.Millisecond * 200 // HALFOPEN_SUCCESSES is the threshold when the breaker is in HALFOPEN; // after secceeding consecutively this times, it will change its state from HALFOPEN to CLOSED; DEFAULT_HALFOPEN_SUCCESSES = 2 // RateTrip Rate DEFAULT_BREAKER_RATE = 0.5 // MinSamples for RateTrip (single instance) DEFAULT_BREAKER_MINSAMPLES = 200 )
View Source
const ( // bucket time is the time each bucket holds DEFAULT_BUCKET_TIME = time.Millisecond * 100 // bucket nums is the number of buckets the container has; DEFAULT_BUCKET_NUMS = 100 )
View Source
const (
// MinQps determines the MinSamples when using AdjustBreakers func
DEFAULT_BREAKER_MINQPS = 200
)
Variables ¶
View Source
var BreakerWhitelist = map[int32]bool{}
Functions ¶
This section is empty.
Types ¶
type Breaker ¶
type Breaker struct { Container // contains all success, error and timeout sync.RWMutex // contains filtered or unexported fields }
func NewBreaker ¶
NewBreaker creates a base breaker with a specified options
func (*Breaker) FailWithTrip ¶
func (*Breaker) Succeed ¶
func (b *Breaker) Succeed()
Succeed records a success and decreases the concurrency counter by one
func (*Breaker) TimeoutWithTrip ¶
type CircuitBreaker ¶
func InitCircuitBreakers ¶
func InitCircuitBreakers(cmds []int32, options Options) (cb CircuitBreaker)
func (*CircuitBreaker) AdjustBreakers ¶
func (b *CircuitBreaker) AdjustBreakers(count int, options Options)
when instances >1, you can use AdjustBreakers count means how many instances you have
func (*CircuitBreaker) GenBreaker ¶
func (b *CircuitBreaker) GenBreaker(cmd int32, options Options) *Breaker
func (*CircuitBreaker) GetAllBreakers ¶
func (b *CircuitBreaker) GetAllBreakers() map[int32]*Breaker
func (*CircuitBreaker) GetBreaker ¶
func (b *CircuitBreaker) GetBreaker(cmd int32) *Breaker
func (*CircuitBreaker) IsTriggerBreaker ¶
func (b *CircuitBreaker) IsTriggerBreaker(cmd int32) bool
type Container ¶
type Container interface { Fail() // records a failure Succeed() // records a success Timeout() // records a timeout Failures() int64 // return the number of failures Successes() int64 // return the number of successes Timeouts() int64 // return the number of timeouts ConsecutiveErrors() int64 // return the consecutive errors recently ErrorRate() float64 // rate = (timeouts + failures) / (timeouts + failures + successes) Samples() int64 // (timeouts + failures + successes) Counts() (successes, failures, timeouts int64) Reset() }
Container contains errors, timeouts and successes
type Options ¶
type Options struct { // parameters for container BucketTime time.Duration // the time each bucket holds BucketNums int // the number of buckets the breaker have // parameters for breaker BreakerRate float64 BreakerMinQPS int // when instance > 1, if qps is over this value, the breaker trip will work BreakerMinSamples int // for RateTrip callback CoolingTimeout time.Duration // fixed when create DetectTimeout time.Duration // fixed when create HalfOpenSuccess int ShouldTrip TripFunc // trip callback, default is RateTrip func StateChangeHandler StateChangeHandler // contains filtered or unexported fields }
Options for Breaker
type StateChangeHandler ¶
StateChangeHandler
Click to show internal directories.
Click to hide internal directories.