MCPcopy Create free account
hub / github.com/zalando/skipper / boundedLoadSearch

Method boundedLoadSearch

loadbalancer/algorithm.go:177–197  ·  view source on GitHub ↗

Returns index of endpoint with closest hash to key's hash, which is also below the target load skipEndpoint function is used to skip endpoints we don't want, for example, fading endpoints

(key string, balanceFactor float64, ctx *routing.LBContext)

Source from the content-addressed store, hash-verified

175// Returns index of endpoint with closest hash to key's hash, which is also below the target load
176// skipEndpoint function is used to skip endpoints we don't want, for example, fading endpoints
177func (ch *consistentHash) boundedLoadSearch(key string, balanceFactor float64, ctx *routing.LBContext) int {
178 ringIndex := ch.searchRing(key, ctx)
179 averageLoad := computeLoadAverage(ctx)
180 targetLoad := averageLoad * balanceFactor
181 // Loop round ring, starting at endpoint with closest hash. Stop when we find one whose load is less than targetLoad.
182 for i := 0; i < ch.Len(); i++ {
183 endpointIndex := ch.hashRing[ringIndex].index
184 if skipEndpoint(ctx, endpointIndex) {
185 continue
186 }
187 load := ctx.Route.LBEndpoints[endpointIndex].Metrics.InflightRequests()
188 // We know there must be an endpoint whose load <= average load.
189 // Since targetLoad >= average load (balancerFactor >= 1), there must also be an endpoint with load <= targetLoad.
190 if float64(load) <= targetLoad {
191 break
192 }
193 ringIndex = (ringIndex + 1) % ch.Len()
194 }
195
196 return ch.hashRing[ringIndex].index
197}
198
199// Apply implements routing.LBAlgorithm with a consistent hash algorithm.
200func (ch *consistentHash) Apply(ctx *routing.LBContext) routing.LBEndpoint {

Callers 1

Calls 5

searchRingMethod · 0.95
LenMethod · 0.95
computeLoadAverageFunction · 0.85
skipEndpointFunction · 0.85
InflightRequestsMethod · 0.65

Tested by

no test coverage detected