balancer

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 License: MIT Imports: 3 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Balancer

type Balancer[T any] interface {
	Select() T
	Add(server T)
	Remove(name string)
}

type SmoothWeightedRoundRobin

type SmoothWeightedRoundRobin[T WeightedServer[T]] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

SmoothWeightedRoundRobin 平滑加权轮询调度器

func NewSmoothWeightedRoundRobin

func NewSmoothWeightedRoundRobin[T WeightedServer[T]](servers []T) *SmoothWeightedRoundRobin[T]

NewSmoothWeightedRoundRobin 创建泛型版平滑加权轮询调度器

func (*SmoothWeightedRoundRobin[T]) Add

func (s *SmoothWeightedRoundRobin[T]) Add(server T)

func (*SmoothWeightedRoundRobin[T]) Remove

func (s *SmoothWeightedRoundRobin[T]) Remove(name string)

func (*SmoothWeightedRoundRobin[T]) Select

func (s *SmoothWeightedRoundRobin[T]) Select() T

Select 选择下一个符合权重规则的服务 返回:选中的泛型服务实例(T类型),无可用服务时返回零值

type WeightedServer

type WeightedServer[T any] interface {
	GetWeight() int              // 获取初始权重(固定)
	GetCurrentWeight() int       // 获取当前权重(动态调整)
	SetCurrentWeight(weight int) // 设置当前权重
	GetName() string             // 获取服务唯一名称(用于增删查)
}

WeightedServer 是泛型约束,要求类型必须实现权重调度所需的核心方法

Jump to

Keyboard shortcuts

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