Version: v0.0.0-...-2321f9d Latest Latest

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

Go to latest
Published: Jul 2, 2017 License: MIT Imports: 2 Imported by: 2



Bounded is Consistent hashing with bounded loads. It acheives that by adding a capacity counter on every host, and when a host gets picked it, checks its capacity to see if it's below the Average Load per Host.

All opertaions in bounded are concurrency-safe.

Average Load Per Host is defined as follows:


totalLoad = sum of all hosts load

load = the number of active requests

imbalance_constant = is the imbalance constant, which is 1.25 in our case

it bounds the load imabalnce to be at most 25% more than (totalLoad/number_of_hosts).

For more info:



This section is empty.


This section is empty.


This section is empty.


type Bounded

type Bounded struct {
	// contains filtered or unexported fields

func New

func New(hosts ...string) *Bounded

func (*Bounded) Add

func (b *Bounded) Add(host string)

func (*Bounded) Balance

func (b *Bounded) Balance(key string) (host string, err error)

err can be liblb.ErrNoHost if there's no added hosts.

func (*Bounded) Done

func (b *Bounded) Done(host string)

should be called when an assigned request to host is finished.

func (*Bounded) Inc

func (b *Bounded) Inc(host string)

It should be called once a request is assigned to a host, obtained from b.Balance.

func (*Bounded) Loads

func (b *Bounded) Loads() map[string]int64

func (*Bounded) MaxLoad

func (b *Bounded) MaxLoad() int64

Max load of a host is (Average Load Per Host*1.25)

func (*Bounded) Remove

func (b *Bounded) Remove(host string)

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto