loadbalancer

package
v0.0.0-...-99cece9 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//DefaultVirualSpots default virual spots
	DefaultVirualSpots = 400
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HashLoadBalancer

type HashLoadBalancer struct {
}

func NewHashLoadBalancer

func NewHashLoadBalancer() *HashLoadBalancer

func (*HashLoadBalancer) SelectService

func (loadBalance *HashLoadBalancer) SelectService(services []*discovery.InstanceInfo) (*discovery.InstanceInfo, error)

func (*HashLoadBalancer) SelectServiceByKey

func (loadBalance *HashLoadBalancer) SelectServiceByKey(services []*discovery.InstanceInfo, key string) (*discovery.InstanceInfo, error)

type HashRing

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

HashRing store nodes and weigths

func NewHashRing

func NewHashRing() *HashRing

NewHashRing create a hash ring with virual spots

func (*HashRing) AddNode

func (h *HashRing) AddNode(nodeKey string, weight int)

AddNode add node to hash ring

func (*HashRing) AddNodes

func (h *HashRing) AddNodes(nodeWeight map[string]int)

AddNodes add nodes to hash ring

func (*HashRing) GetNode

func (h *HashRing) GetNode(s string) string

GetNode get node with key

func (*HashRing) RemoveNode

func (h *HashRing) RemoveNode(nodeKey string)

RemoveNode remove node

func (*HashRing) UpdateNode

func (h *HashRing) UpdateNode(nodeKey string, weight int)

UpdateNode update node with weight

type LoadBalancer

type LoadBalancer interface {
	SelectService(service []*discovery.InstanceInfo) (*discovery.InstanceInfo, error)
	SelectServiceByKey(service []*discovery.InstanceInfo, key string) (*discovery.InstanceInfo, error)
}

负载均衡器

type RandomLoadBalancer

type RandomLoadBalancer struct {
}

func NewRandomLoadBalancer

func NewRandomLoadBalancer() *RandomLoadBalancer

func (*RandomLoadBalancer) SelectService

func (loadBalance *RandomLoadBalancer) SelectService(services []*discovery.InstanceInfo) (*discovery.InstanceInfo, error)

随机负载均衡

func (*RandomLoadBalancer) SelectServiceByKey

func (loadBalance *RandomLoadBalancer) SelectServiceByKey(services []*discovery.InstanceInfo, key string) (*discovery.InstanceInfo, error)

type WeightRoundRobinLoadBalancer

type WeightRoundRobinLoadBalancer struct {
}

func NewWeightRoundRobinLoadBalancer

func NewWeightRoundRobinLoadBalancer() *WeightRoundRobinLoadBalancer

func (*WeightRoundRobinLoadBalancer) SelectService

func (loadBalance *WeightRoundRobinLoadBalancer) SelectService(services []*discovery.InstanceInfo) (best *discovery.InstanceInfo, err error)

权重平滑负载均衡

func (*WeightRoundRobinLoadBalancer) SelectServiceByKey

func (loadBalance *WeightRoundRobinLoadBalancer) SelectServiceByKey(services []*discovery.InstanceInfo, key string) (*discovery.InstanceInfo, error)

Jump to

Keyboard shortcuts

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