Use current resourceUsage value as historyUsage when leader change in ThresholdShedder
### Motivation
Fix
### Modification
1. User current resourceUsage value as historyUsage value when leader change in ThresholdShedder to speed up getting the actual historyUsage value.
@@ -51,13 +51,9 @@ import org.slf4j.LoggerFactory;
*/
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
@@ -153,25 +149,27 @@ public class ThresholdShedder implements LoadSheddingStrategy {
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;
}
}
