Back to godoc.org

Package bounded

v0.0.0-...-2321f9d
Latest Go to latest

The latest major version is .

Published: Jul 2, 2017 | License: MIT | Module: github.com/lafikl/liblb

Overview

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/number_of_hosts)*imbalance_constant

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: https://medium.com/vimeo-engineering-blog/improving-load-balancing-with-a-new-consistent-hashing-algorithm-9f1bd75709ed

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

Index

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)

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier