load_balance

package
v0.0.0-...-132f7fb Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//default check setting
	DefaultCheckMethod    = 0
	DefaultCheckTimeout   = 5
	DefaultCheckMaxErrNum = 2
	DefaultCheckInterval  = 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsistentHashBanlance

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

func NewConsistentHashBanlance

func NewConsistentHashBanlance(replicas int, fn Hash) *ConsistentHashBanlance

func (*ConsistentHashBanlance) Add

func (c *ConsistentHashBanlance) Add(params ...string) error

Add 方法用来添加缓存节点,参数为节点key,比如使用IP

func (*ConsistentHashBanlance) Get

func (c *ConsistentHashBanlance) Get(key string) (string, error)

Get 方法根据给定的对象获取最靠近它的那个节点

func (*ConsistentHashBanlance) IsEmpty

func (c *ConsistentHashBanlance) IsEmpty() bool

验证是否为空

func (*ConsistentHashBanlance) SetConf

func (c *ConsistentHashBanlance) SetConf(conf LoadBalanceConf)

func (*ConsistentHashBanlance) Update

func (c *ConsistentHashBanlance) Update()

type Hash

type Hash func(data []byte) uint32

type LbType

type LbType int
const (
	LbRandom LbType = iota
	LbRoundRobin
	LbWeightRoundRobin
	LbConsistentHash
)

type LoadBalance

type LoadBalance interface {
	Add(...string) error
	Get(string) (string, error)

	//后期服务发现补充
	Update()
}

func LoadBanlanceFactorWithConf

func LoadBanlanceFactorWithConf(lbType LbType, mConf LoadBalanceConf) LoadBalance

func LoadBanlanceFactory

func LoadBanlanceFactory(lbType LbType) LoadBalance

type LoadBalanceCheckConf

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

func NewLoadBalanceCheckConf

func NewLoadBalanceCheckConf(format string, conf map[string]string) (*LoadBalanceCheckConf, error)

func (*LoadBalanceCheckConf) Attach

func (s *LoadBalanceCheckConf) Attach(o Observer)

func (*LoadBalanceCheckConf) GetConf

func (s *LoadBalanceCheckConf) GetConf() []string

func (*LoadBalanceCheckConf) NotifyAllObservers

func (s *LoadBalanceCheckConf) NotifyAllObservers()

func (*LoadBalanceCheckConf) UpdateConf

func (s *LoadBalanceCheckConf) UpdateConf(conf []string)

更新配置时,通知监听者也更新

func (*LoadBalanceCheckConf) WatchConf

func (s *LoadBalanceCheckConf) WatchConf()

更新配置时,通知监听者也更新

type LoadBalanceConf

type LoadBalanceConf interface {
	Attach(o Observer)
	GetConf() []string
	WatchConf()
	UpdateConf(conf []string)
}

配置主题

type Observer

type Observer interface {
	Update()
}

type RandomBalance

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

func (*RandomBalance) Add

func (r *RandomBalance) Add(params ...string) error

func (*RandomBalance) Get

func (r *RandomBalance) Get(key string) (string, error)

func (*RandomBalance) Next

func (r *RandomBalance) Next() string

func (*RandomBalance) SetConf

func (r *RandomBalance) SetConf(conf LoadBalanceConf)

func (*RandomBalance) Update

func (r *RandomBalance) Update()

type RoundRobinBalance

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

func (*RoundRobinBalance) Add

func (r *RoundRobinBalance) Add(params ...string) error

func (*RoundRobinBalance) Get

func (r *RoundRobinBalance) Get(key string) (string, error)

func (*RoundRobinBalance) Next

func (r *RoundRobinBalance) Next() string

func (*RoundRobinBalance) SetConf

func (r *RoundRobinBalance) SetConf(conf LoadBalanceConf)

func (*RoundRobinBalance) Update

func (r *RoundRobinBalance) Update()

type UInt32Slice

type UInt32Slice []uint32

func (UInt32Slice) Len

func (s UInt32Slice) Len() int

func (UInt32Slice) Less

func (s UInt32Slice) Less(i, j int) bool

func (UInt32Slice) Swap

func (s UInt32Slice) Swap(i, j int)

type WeightNode

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

type WeightRoundRobinBalance

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

func (*WeightRoundRobinBalance) Add

func (r *WeightRoundRobinBalance) Add(params ...string) error

func (*WeightRoundRobinBalance) Get

func (r *WeightRoundRobinBalance) Get(key string) (string, error)

func (*WeightRoundRobinBalance) Next

func (r *WeightRoundRobinBalance) Next() string

func (*WeightRoundRobinBalance) SetConf

func (r *WeightRoundRobinBalance) SetConf(conf LoadBalanceConf)

func (*WeightRoundRobinBalance) Update

func (r *WeightRoundRobinBalance) Update()

Jump to

Keyboard shortcuts

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