Documentation ¶
Index ¶
- Variables
- type ConsistentHash
- func (c *ConsistentHash) Add(host string)
- func (c *ConsistentHash) Done(host string)
- func (c *ConsistentHash) Get(key string) (string, error)
- func (c *ConsistentHash) GetHash(hashKey uint32) (string, error)
- func (c *ConsistentHash) GetLeast(key string) (string, error)
- func (c *ConsistentHash) GetLoads() map[string]int64
- func (c *ConsistentHash) GetN(name string, n int) ([]string, error)
- func (c *ConsistentHash) GetTwo(name string) (string, string, error)
- func (c *ConsistentHash) Hosts() (hosts []string)
- func (c *ConsistentHash) Inc(host string)
- func (c *ConsistentHash) MaxLoad() int64
- func (c *ConsistentHash) Members() []string
- func (c *ConsistentHash) Remove(host string) bool
- func (c *ConsistentHash) Set(elts []string)
- func (c *ConsistentHash) SetHashFunc(f HashFunc)
- func (c *ConsistentHash) UpdateLoad(host string, load int64)
- type HashFunc
- type Host
- type Option
- type Options
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoHosts = errors.New("no hosts added")
)
Functions ¶
This section is empty.
Types ¶
type ConsistentHash ¶
func NewConsistentHash ¶
func NewConsistentHash(opts ...Option) *ConsistentHash
func (*ConsistentHash) Add ¶
func (c *ConsistentHash) Add(host string)
func (*ConsistentHash) Done ¶
func (c *ConsistentHash) Done(host string)
Decrements the load of host by 1
should only be used with if you obtained a host with GetLeast
func (*ConsistentHash) Get ¶
func (c *ConsistentHash) Get(key string) (string, error)
Returns the host that owns `key`.
As described in https://en.wikipedia.org/wiki/ConsistentHash_hashing
It returns ErrNoHosts if the ring has no hosts in it.
func (*ConsistentHash) GetLeast ¶
func (c *ConsistentHash) GetLeast(key string) (string, error)
It uses ConsistentHash 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 (*ConsistentHash) GetLoads ¶
func (c *ConsistentHash) GetLoads() map[string]int64
Returns the loads of all the hosts
func (*ConsistentHash) GetN ¶
func (c *ConsistentHash) GetN(name string, n int) ([]string, error)
GetN returns the N closest distinct elements to the name input in the circle.
func (*ConsistentHash) GetTwo ¶
func (c *ConsistentHash) GetTwo(name string) (string, string, error)
GetTwo returns the two closest distinct elements to the name input in the circle.
func (*ConsistentHash) Hosts ¶
func (c *ConsistentHash) Hosts() (hosts []string)
Return the list of hosts in the ring
func (*ConsistentHash) Inc ¶
func (c *ConsistentHash) Inc(host string)
Increments the load of host by 1
should only be used with if you obtained a host with GetLeast
func (*ConsistentHash) MaxLoad ¶
func (c *ConsistentHash) 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 (*ConsistentHash) Members ¶
func (c *ConsistentHash) Members() []string
func (*ConsistentHash) Remove ¶
func (c *ConsistentHash) Remove(host string) bool
Deletes host from the ring
func (*ConsistentHash) Set ¶
func (c *ConsistentHash) Set(elts []string)
Set sets all the elements in the hash. If there are existing elements not present in elts, they will be removed.
func (*ConsistentHash) SetHashFunc ¶
func (c *ConsistentHash) SetHashFunc(f HashFunc)
func (*ConsistentHash) UpdateLoad ¶
func (c *ConsistentHash) UpdateLoad(host string, load int64)
Sets the load of `host` to the given `load`
type Option ¶
type Option func(*Options)