policy

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConnBalancedRatio is the threshold of ratio of the most connection count and least count.
	// If the ratio exceeds the threshold, we migrate connections.
	ConnBalancedRatio = 1.2
	// BalanceCount4Health indicates how many connections to balance per second.
	// If some backends are unhealthy, migrate fast but do not put too much pressure on TiDB.
	BalanceCount4Health = 1000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BackendCtx

type BackendCtx interface {
	Addr() string
	// ConnCount indicates the count of current connections.
	ConnCount() int
	// ConnScore = current connections + incoming connections - outgoing connections.
	ConnScore() int
	Healthy() bool
	Local() bool
	GetBackendInfo() observer.BackendInfo
}

type BalancePolicy

type BalancePolicy interface {
	Init(cfg *config.Config)
	BackendToRoute(backends []BackendCtx) BackendCtx
	// balanceCount is the count of connections to balance per second.
	BackendsToBalance(backends []BackendCtx) (from, to BackendCtx, balanceCount float64, reason string, logFields []zap.Field)
	SetConfig(cfg *config.Config)
}

type SimpleBalancePolicy

type SimpleBalancePolicy struct {
}

SimpleBalancePolicy is used for serverless tier and testing of router. It simply balances by health and connection count.

func NewSimpleBalancePolicy

func NewSimpleBalancePolicy() *SimpleBalancePolicy

func (*SimpleBalancePolicy) BackendToRoute

func (sbp *SimpleBalancePolicy) BackendToRoute(backends []BackendCtx) BackendCtx

func (*SimpleBalancePolicy) BackendsToBalance

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

func (*SimpleBalancePolicy) Init

func (sbp *SimpleBalancePolicy) Init(cfg *config.Config)

func (*SimpleBalancePolicy) SetConfig

func (sbp *SimpleBalancePolicy) SetConfig(cfg *config.Config)

Jump to

Keyboard shortcuts

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