Skip to content

Commit 7635f3c

Browse files
authored
[improve][broker] Optimize ThresholdShedder with improved boundary checks and parameter reuse (#24064)
1 parent f6631be commit 7635f3c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ThresholdShedder.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public synchronized Multimap<String, String> findBundlesForUnloading(final LoadD
119119
}
120120
});
121121
if (selectedBundlesCache.isEmpty() && conf.isLowerBoundarySheddingEnabled()) {
122-
tryLowerBoundaryShedding(loadData, conf);
122+
tryLowerBoundaryShedding(loadData, threshold, conf);
123123
}
124124
return selectedBundlesCache;
125125
}
@@ -182,25 +182,24 @@ private double updateAvgResourceUsage(String broker, LocalBrokerData localBroker
182182
return historyUsage;
183183
}
184184

185-
private void tryLowerBoundaryShedding(LoadData loadData, ServiceConfiguration conf) {
185+
private void tryLowerBoundaryShedding(LoadData loadData, double threshold, ServiceConfiguration conf) {
186186
// Select the broker with the most resource usage.
187-
final double threshold = conf.getLoadBalancerBrokerThresholdShedderPercentage() / 100.0;
188187
final double avgUsage = getBrokerAvgUsage(loadData, conf.getLoadBalancerHistoryResourcePercentage(), conf);
189188
Pair<Boolean, String> result = getMaxUsageBroker(loadData, threshold, avgUsage);
190189
boolean hasBrokerBelowLowerBound = result.getLeft();
191190
String maxUsageBroker = result.getRight();
192-
BrokerData brokerData = loadData.getBrokerData().get(maxUsageBroker);
193-
if (brokerData == null) {
194-
log.info("Load data is null or bundle <=1, skipping bundle unload.");
195-
return;
196-
}
197191
if (!hasBrokerBelowLowerBound) {
198192
log.info("No broker is below the lower bound, threshold is {}, "
199193
+ "avgUsage usage is {}, max usage of Broker {} is {}",
200194
threshold, avgUsage, maxUsageBroker,
201195
brokerAvgResourceUsage.getOrDefault(maxUsageBroker, 0.0));
202196
return;
203197
}
198+
BrokerData brokerData = loadData.getBrokerData().get(maxUsageBroker);
199+
if (brokerData == null) {
200+
log.info("Load data is null or bundle <=1, skipping bundle unload.");
201+
return;
202+
}
204203
LocalBrokerData localData = brokerData.getLocalData();
205204
double brokerCurrentThroughput = localData.getMsgThroughputIn() + localData.getMsgThroughputOut();
206205
double minimumThroughputToOffload = brokerCurrentThroughput * threshold * LOWER_BOUNDARY_THRESHOLD_MARGIN;

0 commit comments

Comments
 (0)