balancers

package
v0.8.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MaxFailures = 5                // 最多失败次数
	SleepWindow = 60 * time.Second // 冷却时间
	MaxRequests = 2                // 在 HalfOpen 状态下, 如果请求成功次数超过此数值,熔断器关闭(恢复);如果有一个失败,重新进入 Open 状态
)

Functions

This section is empty.

Types

type Balancer

type Balancer interface {
	Pop() (uint, error)
	Delete(key uint)
	Reduce(key uint)
	Success(key uint)
}

type Breaker added in v0.6.6

type Breaker struct {
	Balancer
}

func BalancerWrapperBreaker added in v0.6.6

func BalancerWrapperBreaker(balancer Balancer) *Breaker

func (*Breaker) Delete added in v0.6.6

func (b *Breaker) Delete(key uint)

func (*Breaker) Pop added in v0.6.6

func (b *Breaker) Pop() (uint, error)

func (*Breaker) Reduce added in v0.6.6

func (b *Breaker) Reduce(key uint)

func (*Breaker) Success added in v0.6.6

func (b *Breaker) Success(key uint)

type Lottery added in v0.5.31

type Lottery struct {
	// contains filtered or unexported fields
}

按权重概率抽取,类似抽签。

func NewLottery added in v0.5.31

func NewLottery(items map[uint]int) *Lottery

func (*Lottery) Delete added in v0.5.31

func (w *Lottery) Delete(key uint)

func (*Lottery) Pop added in v0.5.31

func (w *Lottery) Pop() (uint, error)

func (*Lottery) Reduce added in v0.5.31

func (w *Lottery) Reduce(key uint)

func (*Lottery) Success added in v0.6.5

func (w *Lottery) Success(key uint)

type Node added in v0.6.6

type Node struct {
	// contains filtered or unexported fields
}

func (*Node) Reset added in v0.6.6

func (n *Node) Reset(state State)

type Rotor added in v0.5.31

type Rotor struct {
	*list.List
	// contains filtered or unexported fields
}

按顺序循环轮转,每次降低权重后移到队尾

func NewRotor added in v0.5.31

func NewRotor(items map[uint]int) *Rotor

func (*Rotor) Delete added in v0.5.31

func (w *Rotor) Delete(key uint)

func (*Rotor) Pop added in v0.5.31

func (w *Rotor) Pop() (uint, error)

func (*Rotor) Reduce added in v0.5.31

func (w *Rotor) Reduce(key uint)

func (*Rotor) Success added in v0.6.5

func (w *Rotor) Success(key uint)

type State added in v0.6.6

type State int
const (
	StateClosed   State = iota // 正常运行
	StateOpen                  // 熔断触发
	StateHalfOpen              // 探测恢复
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL