selector

package
v0.0.0-...-9835270 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: AGPL-3.0, Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoKeys = errors.New("no keys added")

Functions

func NewConsistent

func NewConsistent(conf interface{}) (core.ISelector, error)

func NewConsistentWithBoundedLoad

func NewConsistentWithBoundedLoad(conf interface{}) (core.ISelector, error)

Types

type Consistent

type Consistent struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Consistent) AddNode

func (c *Consistent) AddNode(host string)

func (*Consistent) DelNode

func (c *Consistent) DelNode(host string) bool

Deletes host from the ring

func (*Consistent) GetName

func (c *Consistent) GetName() string

func (*Consistent) GetNode

func (c *Consistent) GetNode(key string) (string, error)

Returns the host that owns `key`.

As described in https://en.wikipedia.org/wiki/Consistent_hashing

It returns ErrNoKeys if the ring has no hosts in it.

type ConsistentWithBoundedLoad

type ConsistentWithBoundedLoad struct {
	Consistent

	sync.RWMutex
	// contains filtered or unexported fields
}

func (*ConsistentWithBoundedLoad) Done

func (c *ConsistentWithBoundedLoad) Done(host string)

Decrements the load of host by 1

should only be used with if you obtained a host with GetLeast

func (*ConsistentWithBoundedLoad) GetNode

func (c *ConsistentWithBoundedLoad) GetNode(key string) (string, error)

It uses Consistent Hashing With Bounded loads

https://research.googleblog.com/2017/04/consistent-hashing-with-bounded-loads.html

to pick the least loaded host that can serve the key

It returns ErrNoHosts if the ring has no hosts in it.

func (*ConsistentWithBoundedLoad) Inc

func (c *ConsistentWithBoundedLoad) Inc(host string)

Increments the load of host by 1

should only be used with if you obtained a host with GetLeast

func (*ConsistentWithBoundedLoad) MaxLoad

func (c *ConsistentWithBoundedLoad) MaxLoad() int64

Returns the maximum load of the single host which is: (total_load/number_of_hosts)*1.25 total_load = is the total number of active requests served by hosts for more info: https://research.googleblog.com/2017/04/consistent-hashing-with-bounded-loads.html

func (*ConsistentWithBoundedLoad) Remove

func (c *ConsistentWithBoundedLoad) Remove(host string) bool

Deletes host from the ring

func (*ConsistentWithBoundedLoad) UpdateLoad

func (c *ConsistentWithBoundedLoad) UpdateLoad(host string, load int64)

Sets the load of `host` to the given `load`

Jump to

Keyboard shortcuts

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