Documentation ¶
Index ¶
Constants ¶
const ( DefaultTableSize = 16381 // seed=$(head -c12 /dev/urandom | base64 -w0) DefaultHashSeed = "JLfvgnHc2kaSUFaI" )
Variables ¶
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.
Types ¶
This section is empty.