balance

package
v0.0.0-...-a36dcc1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: MIT Imports: 5 Imported by: 0

README

介绍

用于分布式资源消费方调用某个实例时的负载均衡策略算法,应用场景:服务网关,资源调度等

实现

  • 一致性hash算法

reference

  1. 一致性hash算法原理及golang实现

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hash

type Hash func(data []byte) uint32

type HashRing

type HashRing struct {
	Nodes map[uint32]string // 节点哈希和KEY的HashRing,键是哈希值,值是节点Key
	// contains filtered or unexported fields
}

func NewHashRing

func NewHashRing() *HashRing

func (*HashRing) AddNodes

func (hashRing *HashRing) AddNodes(nodes ...string)

Add 方法用来添加缓存节点,参数为节点key,比如使用IP

func (*HashRing) GetNode

func (hashRing *HashRing) GetNode(key string) string

Get 方法根据给定的对象获取最靠近它的那个节点key

func (*HashRing) IsEmpty

func (hashRing *HashRing) IsEmpty() bool

type UInt32Slice

type UInt32Slice []uint32

func (UInt32Slice) Len

func (s UInt32Slice) Len() int

func (UInt32Slice) Less

func (s UInt32Slice) Less(i, j int) bool

func (UInt32Slice) Swap

func (s UInt32Slice) Swap(i, j int)

Jump to

Keyboard shortcuts

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