Skip to content

Commit

Permalink
Use current resourceUsage value as historyUsage when leader change in…
Browse files Browse the repository at this point in the history
… ThresholdShedder (#13136)

### Motivation
Fix #13119

### Modification
1. User current resourceUsage value as historyUsage value when leader change in ThresholdShedder to speed up getting the actual historyUsage value.

(cherry picked from commit 6d9d24d)
  • Loading branch information
hangc0276 authored and zymap committed Dec 23, 2021
1 parent ef4c7f7 commit 85c4ba0
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@

public class ThresholdShedder implements LoadSheddingStrategy {
private static final Logger log = LoggerFactory.getLogger(ThresholdShedder.class);

private final Multimap<String, String> selectedBundlesCache = ArrayListMultimap.create();

private static final double ADDITIONAL_THRESHOLD_PERCENT_MARGIN = 0.05;

private static final double MB = 1024 * 1024;

private final Map<String, Double> brokerAvgResourceUsage = new HashMap<>();

@Override
Expand Down Expand Up @@ -139,25 +135,27 @@ private double getBrokerAvgUsage(final LoadData loadData, final double historyPe
for (Map.Entry<String, BrokerData> entry : loadData.getBrokerData().entrySet()) {
LocalBrokerData localBrokerData = entry.getValue().getLocalData();
String broker = entry.getKey();
updateAvgResourceUsage(broker, localBrokerData, historyPercentage, conf);
totalUsage += brokerAvgResourceUsage.getOrDefault(broker, 0.0);
totalUsage += updateAvgResourceUsage(broker, localBrokerData, historyPercentage, conf);
totalBrokers++;
}

return totalBrokers > 0 ? totalUsage / totalBrokers : 0;
}

private void updateAvgResourceUsage(String broker, LocalBrokerData localBrokerData, final double historyPercentage,
final ServiceConfiguration conf) {
double historyUsage =
brokerAvgResourceUsage.getOrDefault(broker, 0.0);
historyUsage = historyUsage * historyPercentage
+ (1 - historyPercentage) * localBrokerData.getMaxResourceUsageWithWeight(
private double updateAvgResourceUsage(String broker, LocalBrokerData localBrokerData,
final double historyPercentage, final ServiceConfiguration conf) {
Double historyUsage =
brokerAvgResourceUsage.get(broker);
double resourceUsage = localBrokerData.getMaxResourceUsageWithWeight(
conf.getLoadBalancerCPUResourceWeight(),
conf.getLoadBalancerMemoryResourceWeight(), conf.getLoadBalancerDirectMemoryResourceWeight(),
conf.getLoadBalancerBandwithInResourceWeight(),
conf.getLoadBalancerBandwithOutResourceWeight());
historyUsage = historyUsage == null
? resourceUsage : historyUsage * historyPercentage + (1 - historyPercentage) * resourceUsage;

brokerAvgResourceUsage.put(broker, historyUsage);
return historyUsage;
}

}

0 comments on commit 85c4ba0

Please sign in to comment.