Documentation ¶
Overview ¶
Package maghash implements Google's load balance solution - Maglev's consistent hashing algorithm. ref:
http://static.googleusercontent.com/media/research.google.com/zh-CN//pubs/archive/44824.pdf
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( //ErrInvalidIndex indicates invalid index ErrInvalidIndex = errors.New("invalid index") //ErrInvalidPrime indicates invalid prime number ErrInvalidPrime = errors.New("invalid prime number") )
Functions ¶
This section is empty.
Types ¶
type MagHash ¶
type MagHash interface { // Add backends to Maglev hashing, those added items will be considered // as available backends. This will internally RW lock backend related // data structures. It will trigger a permutation and lookup table re-calculation AddBackends(backends []string) (err error) // Remove backends from backend list, we don't need recalculate permutation // but a lookup table populate is required. RemoveBackends(backends []string) // Get the current number of backends. BackendsNum() (count int) // Get the m value for hash calculation. M() (m int) // Get the backend lookup result for given flow. GetBackend(flow string) (backend string) // Get the lookup table (list of backends) LookupTable() (backends []string) }
MagHash is an interface providing Maglev Hashing functions
func NewMagHash ¶
NewMagHash creates Maghash with M, M must larger than backend number. A greater M value increasing backend selection equalization while decreasing performance.
Click to show internal directories.
Click to hide internal directories.