balancer

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

接口文件 balancer 负载均衡

实现文件 balancernormal 负载均衡管理器,主要用于统筹管理 服务:负载均衡算法

实现文件 brandom 随机负载均衡算法实现

实现文件 balancerswrr 平滑加权负载均衡算法实现

Index

Constants

View Source
const (
	// Name 基础的负载均衡容器实现
	Name = "BalancerNormal"

	StrategyRandom = "strategy_random"
	StrategySwrr   = "strategy_swrr"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type IBalancer

type IBalancer interface {
	Init()

	// Pick 为 target 服务选取一个合适的节点
	//
	// strategy 选取所使用的策略,在构建阶段通过 opt 传入
	Pick(strategy string, target string) (meta.Node, error)

	Run()

	Close()
}

IBalancer 负载均衡器

func BuildWithOption

func BuildWithOption(info meta.ServiceInfo, log *blog.Logger, ps module.IPubsub, opts ...Option) IBalancer

type IPicker

type IPicker interface {
	// Get 从当前的负载均衡算法中,选取一个匹配的节点
	Get() (nod meta.Node, err error)

	// Add 为当前的服务添加一个新的节点 service gate : [ gate1, gate2 ]
	Add(meta.Node)

	// Rmv 从当前的服务中移除一个旧的节点
	Rmv(meta.Node)

	// Update 更新一个当前服务中的节点(通常是权重信息
	Update(meta.Node)
}

IPicker 选取器

type Option

type Option func(*Parm)

Option parm opt

func WithStrategy

func WithStrategy(strategies []string) Option

WithStrategy add strategy

type Parm

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

Parm balancer group parm

Jump to

Keyboard shortcuts

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