Skip to content

Commit acd3425

Browse files
fixed verbose work in updateWeightSS(), float equality
1 parent dc7960a commit acd3425

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

xds/src/main/java/io/grpc/xds/WeightedRoundRobinLoadBalancer.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -317,27 +317,11 @@ private void updateWeightEdf() {
317317

318318
// verbose work done (requires optimization)
319319
private void updateWeightSS() {
320-
int weightedChannelCount = 0;
321-
double avgWeight = 0;
322-
for (Subchannel value : list) {
323-
double newWeight = ((WrrSubchannel) value).getWeight();
324-
if (newWeight > 0) {
325-
avgWeight += newWeight;
326-
weightedChannelCount++;
327-
}
328-
}
329-
330-
if (weightedChannelCount >= 1) {
331-
avgWeight /= 1.0 * weightedChannelCount;
332-
} else {
333-
avgWeight = 1;
334-
}
335-
336320
float[] newWeights = new float[list.size()];
337321
for (int i = 0; i < list.size(); i++) {
338322
WrrSubchannel subchannel = (WrrSubchannel) list.get(i);
339323
double newWeight = subchannel.getWeight();
340-
newWeights[i] = newWeight > 0 ? (float) newWeight : (float) avgWeight;
324+
newWeights[i] = newWeight > 0 ? (float) newWeight : 0.0f;
341325
}
342326

343327
StaticStrideScheduler ssScheduler = new StaticStrideScheduler(newWeights);
@@ -485,7 +469,7 @@ static final class StaticStrideScheduler {
485469
double sumWeight = 0;
486470
float maxWeight = 0;
487471
for (float weight : weights) {
488-
if (weight == 0) {
472+
if (Math.abs(weight - 0.0) < 0.0001) {
489473
numZeroWeightChannels++;
490474
}
491475
sumWeight += weight;

0 commit comments

Comments
 (0)