maglev

package
v1.16.2 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

View Source
const (
	DefaultTableSize = 16381

	// seed=$(head -c12 /dev/urandom | base64 -w0)
	DefaultHashSeed = "JLfvgnHc2kaSUFaI"
)

Variables

View Source
var (
	SeedJhash0 uint32
	SeedJhash1 uint32
)

Functions

func GetLookupTable

func GetLookupTable(backendsMap map[string]*loadbalancer.Backend, m uint64) []int

GetLookupTable returns the Maglev lookup table of the size "m" for the given backends. The lookup table contains the IDs of the given backends.

Maglev algorithm might produce different lookup table for the same set of backends listed in a different order. To avoid that sort backends by name, as the names are the same on all nodes (in opposite to backend IDs which are node-local).

The weights implementation is inspired by https://github.com/envoyproxy/envoy/pull/2982.

A backend weight is honored by altering the frequency how often a backend's turn is selected. A backend weight is multiplied in each turn by (n + 1) and compared to weightCntr[backendName] value which is an incrementation of weightSum (but starts at backend's weight / number of backends, so that each backend is selected at least once). If this is lower than weightCntr[backendName], another backend has a turn (and weightCntr[backendName] is incremented). This way we honor the weights.

func Init

func Init(seed string, m uint64) error

Init initializes the Maglev subsystem with the seed and the backend table size (m).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL