@@ -75,17 +75,15 @@ func shiftWeighted(rnd *rand.Rand, ctx *routing.LBContext, now time.Time) routin
75
75
rt := ctx .Route
76
76
ep := ctx .LBEndpoints
77
77
for _ , epi := range ep {
78
- detected := ctx .Registry .GetMetrics (epi .Host ).DetectedTime ()
79
- wi := fadeIn (now , rt .LBFadeInDuration , rt .LBFadeInExponent , detected )
78
+ wi := fadeIn (now , rt .LBFadeInDuration , rt .LBFadeInExponent , epi .Detected )
80
79
sum += wi
81
80
}
82
81
83
82
choice := ep [len (ep )- 1 ]
84
83
r := rnd .Float64 () * sum
85
84
var upto float64
86
85
for i , epi := range ep {
87
- detected := ctx .Registry .GetMetrics (epi .Host ).DetectedTime ()
88
- upto += fadeIn (now , rt .LBFadeInDuration , rt .LBFadeInExponent , detected )
86
+ upto += fadeIn (now , rt .LBFadeInDuration , rt .LBFadeInExponent , epi .Detected )
89
87
if upto > r {
90
88
choice = ep [i ]
91
89
break
@@ -114,21 +112,19 @@ func shiftToRemaining(rnd *rand.Rand, ctx *routing.LBContext, wi []int, now time
114
112
func withFadeIn (rnd * rand.Rand , ctx * routing.LBContext , choice int , algo routing.LBAlgorithm ) routing.LBEndpoint {
115
113
ep := ctx .LBEndpoints
116
114
now := time .Now ()
117
- detected := ctx .Registry .GetMetrics (ctx .LBEndpoints [choice ].Host ).DetectedTime ()
118
115
f := fadeIn (
119
116
now ,
120
117
ctx .Route .LBFadeInDuration ,
121
118
ctx .Route .LBFadeInExponent ,
122
- detected ,
119
+ ctx . LBEndpoints [ choice ]. Detected ,
123
120
)
124
121
125
122
if rnd .Float64 () < f {
126
123
return ep [choice ]
127
124
}
128
125
notFadingIndexes := make ([]int , 0 , len (ep ))
129
126
for i := 0 ; i < len (ep ); i ++ {
130
- detected := ctx .Registry .GetMetrics (ep [i ].Host ).DetectedTime ()
131
- if _ , fadingIn := fadeInState (now , ctx .Route .LBFadeInDuration , detected ); ! fadingIn {
127
+ if _ , fadingIn := fadeInState (now , ctx .Route .LBFadeInDuration , ep [i ].Detected ); ! fadingIn {
132
128
notFadingIndexes = append (notFadingIndexes , i )
133
129
}
134
130
}
@@ -267,7 +263,7 @@ func computeLoadAverage(ctx *routing.LBContext) float64 {
267
263
sum := 1.0 // add 1 to include the request that just arrived
268
264
endpoints := ctx .LBEndpoints
269
265
for _ , v := range endpoints {
270
- sum += float64 (ctx . Registry . GetMetrics ( v . Host ). InflightRequests ())
266
+ sum += float64 (v . Metrics . GetInflightRequests ())
271
267
}
272
268
return sum / float64 (len (endpoints ))
273
269
}
@@ -284,10 +280,10 @@ func (ch *consistentHash) boundedLoadSearch(key string, balanceFactor float64, c
284
280
if skipEndpoint (endpointIndex ) {
285
281
continue
286
282
}
287
- load := ctx .Registry . GetMetrics ( ctx . LBEndpoints [endpointIndex ].Host ). InflightRequests ()
283
+ load := ctx .LBEndpoints [endpointIndex ].Metrics . GetInflightRequests ()
288
284
// We know there must be an endpoint whose load <= average load.
289
285
// Since targetLoad >= average load (balancerFactor >= 1), there must also be an endpoint with load <= targetLoad.
290
- if load <= int64 (targetLoad ) {
286
+ if load <= int (targetLoad ) {
291
287
break
292
288
}
293
289
ringIndex = (ringIndex + 1 ) % ch .Len ()
@@ -369,17 +365,17 @@ func (p *powerOfRandomNChoices) Apply(ctx *routing.LBContext) routing.LBEndpoint
369
365
for i := 1 ; i < p .numberOfChoices ; i ++ {
370
366
ce := ctx .LBEndpoints [p .rnd .Intn (ne )]
371
367
372
- if p .getScore (ctx , ce ) > p .getScore (ctx , best ) {
368
+ if p .getScore (ce ) > p .getScore (best ) {
373
369
best = ce
374
370
}
375
371
}
376
372
return best
377
373
}
378
374
379
375
// getScore returns negative value of inflightrequests count.
380
- func (p * powerOfRandomNChoices ) getScore (ctx * routing. LBContext , e routing.LBEndpoint ) int64 {
376
+ func (p * powerOfRandomNChoices ) getScore (e routing.LBEndpoint ) int64 {
381
377
// endpoints with higher inflight request should have lower score
382
- return - ctx . Registry . GetMetrics (e .Host ). InflightRequests ( )
378
+ return - int64 (e .Metrics . GetInflightRequests () )
383
379
}
384
380
385
381
type (
0 commit comments