factor

package
v1.3.1-beta.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factor

type Factor interface {
	// Name returns the name of the factor.
	Name() string
	// UpdateScore updates the score of each backend.
	UpdateScore(backends []scoredBackend)
	// ScoreBitNum returns the bit number of the score.
	ScoreBitNum() int
	// BalanceCount returns the count of connections to balance per second.
	// 0 indicates the factor is already balanced.
	BalanceCount(from, to scoredBackend) (float64, []zap.Field)
	SetConfig(cfg *config.Config)
	// CanBeRouted returns whether a connection can be routed or migrated to the backend with the score.
	CanBeRouted(score uint64) bool
	Close()
}

type FactorBasedBalance

type FactorBasedBalance struct {
	sync.Mutex
	// contains filtered or unexported fields
}

FactorBasedBalance is the default balance policy.

func (*FactorBasedBalance) BackendToRoute

func (fbb *FactorBasedBalance) BackendToRoute(backends []policy.BackendCtx) policy.BackendCtx

BackendToRoute returns one backend to route a new connection to.

func (*FactorBasedBalance) BackendsToBalance

func (fbb *FactorBasedBalance) BackendsToBalance(backends []policy.BackendCtx) (from, to policy.BackendCtx, balanceCount float64, reason string, logFields []zap.Field)

BackendsToBalance returns the busiest/unhealthy backend and the idlest backend. balanceCount: the count of connections to migrate in this round. 0 indicates no need to balance. reason: the debug information to be logged.

func (*FactorBasedBalance) Close

func (fbb *FactorBasedBalance) Close()

func (*FactorBasedBalance) Init

func (fbb *FactorBasedBalance) Init(cfg *config.Config)

Init creates factors at the first time. TODO: create factors according to config and update policy when config changes.

func (*FactorBasedBalance) SetConfig

func (fbb *FactorBasedBalance) SetConfig(cfg *config.Config)

type FactorCPU

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

func NewFactorCPU

func NewFactorCPU(mr metricsreader.MetricsReader, lg *zap.Logger) *FactorCPU

func (*FactorCPU) BalanceCount

func (fc *FactorCPU) BalanceCount(from, to scoredBackend) (float64, []zap.Field)

func (*FactorCPU) CanBeRouted added in v1.3.1

func (fc *FactorCPU) CanBeRouted(_ uint64) bool

func (*FactorCPU) Close

func (fc *FactorCPU) Close()

func (*FactorCPU) Name

func (fc *FactorCPU) Name() string

func (*FactorCPU) ScoreBitNum

func (fc *FactorCPU) ScoreBitNum() int

func (*FactorCPU) SetConfig

func (fc *FactorCPU) SetConfig(cfg *config.Config)

func (*FactorCPU) UpdateScore

func (fc *FactorCPU) UpdateScore(backends []scoredBackend)

type FactorConnCount

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

FactorConnCount balances by connection count and must be used in following cases: - The policy is set to `connection` - The backend CPU usages are unavailable - The workload just starts and the backend CPU usages are low

func NewFactorConnCount

func NewFactorConnCount() *FactorConnCount

func (*FactorConnCount) BalanceCount

func (fcc *FactorConnCount) BalanceCount(from, to scoredBackend) (float64, []zap.Field)

func (*FactorConnCount) CanBeRouted added in v1.3.1

func (fcc *FactorConnCount) CanBeRouted(_ uint64) bool

func (*FactorConnCount) Close

func (fcc *FactorConnCount) Close()

func (*FactorConnCount) Name

func (fcc *FactorConnCount) Name() string

func (*FactorConnCount) ScoreBitNum

func (fcc *FactorConnCount) ScoreBitNum() int

func (*FactorConnCount) SetConfig

func (fcc *FactorConnCount) SetConfig(cfg *config.Config)

func (*FactorConnCount) UpdateScore

func (fcc *FactorConnCount) UpdateScore(backends []scoredBackend)

type FactorHealth

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

func NewFactorHealth

func NewFactorHealth(mr metricsreader.MetricsReader, lg *zap.Logger) *FactorHealth

func (*FactorHealth) BalanceCount

func (fh *FactorHealth) BalanceCount(from, to scoredBackend) (float64, []zap.Field)

func (*FactorHealth) CanBeRouted added in v1.3.1

func (fh *FactorHealth) CanBeRouted(_ uint64) bool

func (*FactorHealth) Close

func (fh *FactorHealth) Close()

func (*FactorHealth) Name

func (fh *FactorHealth) Name() string

func (*FactorHealth) ScoreBitNum

func (fh *FactorHealth) ScoreBitNum() int

func (*FactorHealth) SetConfig

func (fh *FactorHealth) SetConfig(cfg *config.Config)

func (*FactorHealth) UpdateScore

func (fh *FactorHealth) UpdateScore(backends []scoredBackend)

type FactorLabel

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

func NewFactorLabel

func NewFactorLabel() *FactorLabel

func (*FactorLabel) BalanceCount

func (fl *FactorLabel) BalanceCount(from, to scoredBackend) (float64, []zap.Field)

func (*FactorLabel) CanBeRouted added in v1.3.1

func (fl *FactorLabel) CanBeRouted(score uint64) bool

func (*FactorLabel) Close

func (fl *FactorLabel) Close()

func (*FactorLabel) Name

func (fl *FactorLabel) Name() string

func (*FactorLabel) ScoreBitNum

func (fl *FactorLabel) ScoreBitNum() int

func (*FactorLabel) SetConfig

func (fl *FactorLabel) SetConfig(cfg *config.Config)

func (*FactorLabel) UpdateScore

func (fl *FactorLabel) UpdateScore(backends []scoredBackend)

type FactorLocation

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

func NewFactorLocation

func NewFactorLocation() *FactorLocation

func (*FactorLocation) BalanceCount

func (fl *FactorLocation) BalanceCount(from, to scoredBackend) (float64, []zap.Field)

func (*FactorLocation) CanBeRouted added in v1.3.1

func (fl *FactorLocation) CanBeRouted(_ uint64) bool

func (*FactorLocation) Close

func (fl *FactorLocation) Close()

func (*FactorLocation) Name

func (fl *FactorLocation) Name() string

func (*FactorLocation) ScoreBitNum

func (fl *FactorLocation) ScoreBitNum() int

func (*FactorLocation) SetConfig

func (fl *FactorLocation) SetConfig(cfg *config.Config)

func (*FactorLocation) UpdateScore

func (fl *FactorLocation) UpdateScore(backends []scoredBackend)

type FactorMemory

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

func NewFactorMemory

func NewFactorMemory(mr metricsreader.MetricsReader, lg *zap.Logger) *FactorMemory

func (*FactorMemory) BalanceCount

func (fm *FactorMemory) BalanceCount(from, to scoredBackend) (float64, []zap.Field)

func (*FactorMemory) CanBeRouted added in v1.3.1

func (fm *FactorMemory) CanBeRouted(_ uint64) bool

func (*FactorMemory) Close

func (fm *FactorMemory) Close()

func (*FactorMemory) Name

func (fm *FactorMemory) Name() string

func (*FactorMemory) ScoreBitNum

func (fm *FactorMemory) ScoreBitNum() int

func (*FactorMemory) SetConfig

func (fm *FactorMemory) SetConfig(cfg *config.Config)

func (*FactorMemory) UpdateScore

func (fm *FactorMemory) UpdateScore(backends []scoredBackend)

type FactorStatus

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

func NewFactorStatus

func NewFactorStatus(lg *zap.Logger) *FactorStatus

func (*FactorStatus) BalanceCount

func (fs *FactorStatus) BalanceCount(from, to scoredBackend) (float64, []zap.Field)

func (*FactorStatus) CanBeRouted added in v1.3.1

func (fl *FactorStatus) CanBeRouted(score uint64) bool

func (*FactorStatus) Close

func (fs *FactorStatus) Close()

func (*FactorStatus) Name

func (fs *FactorStatus) Name() string

func (*FactorStatus) ScoreBitNum

func (fs *FactorStatus) ScoreBitNum() int

func (*FactorStatus) SetConfig

func (fs *FactorStatus) SetConfig(cfg *config.Config)

func (*FactorStatus) UpdateScore

func (fs *FactorStatus) UpdateScore(backends []scoredBackend)

Jump to

Keyboard shortcuts

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