diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/UniformLoadShedder.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/UniformLoadShedder.java index 8133f432ac4c4..3762cf62c1017 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/UniformLoadShedder.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/UniformLoadShedder.java @@ -49,6 +49,8 @@ public class UniformLoadShedder implements LoadSheddingStrategy { private static final Logger log = LoggerFactory.getLogger(UniformLoadShedder.class); + private static final double MB = 1024 * 1024; + private final Multimap selectedBundlesCache = ArrayListMultimap.create(); /** @@ -73,6 +75,9 @@ public Multimap findBundlesForUnloading(final LoadData loadData, MutableDouble maxThroughputRate = new MutableDouble(-1); MutableDouble minMsgRate = new MutableDouble(Integer.MAX_VALUE); MutableDouble minThroughputgRate = new MutableDouble(Integer.MAX_VALUE); + + double minThroughputThreshold = conf.getLoadBalancerBundleUnloadMinThroughputThreshold() * MB; + brokersData.forEach((broker, data) -> { double msgRate = data.getLocalData().getMsgRateIn() + data.getLocalData().getMsgRateOut(); double throughputRate = data.getLocalData().getMsgThroughputIn() @@ -122,6 +127,15 @@ public Multimap findBundlesForUnloading(final LoadData loadData, (int) ((maxThroughputRate.getValue() - minThroughputgRate.getValue()) / 2)); LocalBrokerData overloadedBrokerData = brokersData.get(overloadedBroker.getValue()).getLocalData(); + if (msgThroughtputRequiredFromUnloadedBundles.getValue() < minThroughputThreshold) { + if (log.isDebugEnabled()) { + log.debug("Planning to shed throughput {} MByte/s less than " + + "minimumThroughputThreshold {} MByte/s, stop unload.", + msgThroughtputRequiredFromUnloadedBundles.getValue() / MB, minThroughputThreshold / MB); + } + return selectedBundlesCache; + } + if (overloadedBrokerData.getBundles().size() > 1) { // Sort bundles by throughput, then pick the bundle which can help to reduce load uniformly with // under-loaded broker