Skip to content

Commit

Permalink
Move trackersWithVolume() to SuccessRateOutlierEjectionAlgorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
temawi committed Aug 16, 2022
1 parent b438bf7 commit 605d8e5
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions core/src/main/java/io/grpc/util/OutlierDetectionLoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -649,17 +649,6 @@ void maybeUnejectOutliers(Long detectionTimerStartNanos) {
}
}

/** Returns only the trackers that have the minimum configured volume to be considered. */
List<AddressTracker> trackersWithVolume(OutlierDetectionLoadBalancerConfig config) {
List<AddressTracker> trackersWithVolume = new ArrayList<>();
for (AddressTracker tracker : trackerMap.values()) {
if (tracker.inactiveVolume() >= config.successRateEjection.requestVolume) {
trackersWithVolume.add(tracker);
}
}
return trackersWithVolume;
}

/**
* How many percent of the addresses would have their subchannels ejected if we proceeded
* with the next ejection.
Expand Down Expand Up @@ -720,7 +709,7 @@ static class SuccessRateOutlierEjectionAlgorithm implements OutlierEjectionAlgor
public void ejectOutliers(AddressTrackerMap trackerMap, long ejectionTimeNanos) {

// Only consider addresses that have the minimum request volume specified in the config.
List<AddressTracker> trackersWithVolume = trackerMap.trackersWithVolume(config);
List<AddressTracker> trackersWithVolume = trackersWithVolume(trackerMap, config);
// If we don't have enough addresses with significant volume then there's nothing to do.
if (trackersWithVolume.size() < config.successRateEjection.minimumHosts
|| trackersWithVolume.size() == 0) {
Expand Down Expand Up @@ -753,7 +742,20 @@ public void ejectOutliers(AddressTrackerMap trackerMap, long ejectionTimeNanos)
}
}

/** Returns only the trackers that have the minimum configured volume to be considered. */
private List<AddressTracker> trackersWithVolume(AddressTrackerMap trackerMap,
OutlierDetectionLoadBalancerConfig config) {
List<AddressTracker> trackersWithVolume = new ArrayList<>();
for (AddressTracker tracker : trackerMap.values()) {
if (tracker.inactiveVolume() >= config.successRateEjection.requestVolume) {
trackersWithVolume.add(tracker);
}
}
return trackersWithVolume;
}

/** Calculates the mean of the given values. */
@VisibleForTesting
static double mean(Collection<Double> values) {
double totalValue = 0;
for (double value : values) {
Expand All @@ -764,6 +766,7 @@ static double mean(Collection<Double> values) {
}

/** Calculates the standard deviation for the given values and their mean. */
@VisibleForTesting
static double standardDeviation(Collection<Double> values, double mean) {
double squaredDifferenceSum = 0;
for (double value : values) {
Expand Down

0 comments on commit 605d8e5

Please sign in to comment.