Documentation ¶
Index ¶
- Variables
- func NewConsistent(conf interface{}) (core.ISelector, error)
- func NewConsistentWithBoundedLoad(conf interface{}) (core.ISelector, error)
- type Consistent
- type ConsistentWithBoundedLoad
- func (c *ConsistentWithBoundedLoad) Done(host string)
- func (c *ConsistentWithBoundedLoad) GetNode(key string) (string, error)
- func (c *ConsistentWithBoundedLoad) Inc(host string)
- func (c *ConsistentWithBoundedLoad) MaxLoad() int64
- func (c *ConsistentWithBoundedLoad) Remove(host string) bool
- func (c *ConsistentWithBoundedLoad) UpdateLoad(host string, load int64)
Constants ¶
This section is empty.
Variables ¶
var ErrNoKeys = errors.New("no keys added")
Functions ¶
func NewConsistent ¶
Types ¶
type Consistent ¶
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`