Consistent uses consistent hashing algorithm to assign work to hosts. Its best for the cases when you need affinty, and your hosts come and go. When removing a host it gaurantees that only 1/n of items gets reshuffled where n is the number of servers.

    One of the issues with Consistent Hashing is load imbalance when you have hot keys that goes to a single server, it's mitigated by using virtual nodes, which basically means when adding a host we add n - 20 in our case - replicas of that host.

    Beware that Consistent Hashing doesn't provide, an upper bound for the load of a host.

    If you need such gaurantees see package liblb/bounded.



    This section is empty.


    This section is empty.


    This section is empty.


    type Consistent

    type Consistent struct {
    	// contains filtered or unexported fields

    func New

    func New(hosts ...string) *Consistent

    func (*Consistent) Add

    func (c *Consistent) Add(host string)

    func (*Consistent) Balance

    func (h *Consistent) Balance(key string) (host string, err error)

    func (*Consistent) Remove

    func (c *Consistent) Remove(host string)

    Source Files