Search in sources :

Example 1 with TimeAverageMessageData

use of org.apache.pulsar.policies.data.loadbalancer.TimeAverageMessageData in project pulsar by yahoo.

the class OverloadShedderTest method testBrokerWithMultipleBundles.

@Test
public void testBrokerWithMultipleBundles() {
    int numBundles = 10;
    LoadData loadData = new LoadData();
    LocalBrokerData broker1 = new LocalBrokerData();
    broker1.setBandwidthIn(new ResourceUsage(999, 1000));
    broker1.setBandwidthOut(new ResourceUsage(999, 1000));
    LocalBrokerData anotherBroker = new LocalBrokerData();
    String anotherBrokerName = "another-broker";
    double brokerThroghput = 0;
    for (int i = 1; i <= numBundles; i++) {
        broker1.getBundles().add("bundle-" + i);
        BundleData bundle = new BundleData();
        TimeAverageMessageData db = new TimeAverageMessageData();
        double throughput = i * 1024 * 1024;
        db.setMsgThroughputIn(throughput);
        db.setMsgThroughputOut(throughput);
        bundle.setShortTermData(db);
        loadData.getBundleData().put("bundle-" + i, bundle);
        // This bundle should not be selected for `broker1` since it is belong to another broker.
        String anotherBundleName = anotherBrokerName + "-bundle-" + (numBundles + i);
        loadData.getBundleData().put(anotherBundleName, bundle);
        anotherBroker.getBundles().add(anotherBundleName);
        brokerThroghput += throughput;
    }
    broker1.setMsgThroughputIn(brokerThroghput);
    broker1.setMsgThroughputOut(brokerThroghput);
    loadData.getBrokerData().put("broker-1", new BrokerData(broker1));
    loadData.getBrokerData().put(anotherBrokerName, new BrokerData(anotherBroker));
    Multimap<String, String> bundlesToUnload = os.findBundlesForUnloading(loadData, conf);
    assertFalse(bundlesToUnload.isEmpty());
    assertEquals(bundlesToUnload.get("broker-1"), Lists.newArrayList("bundle-10", "bundle-9"));
}
Also used : LoadData(org.apache.pulsar.broker.loadbalance.LoadData) LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) BrokerData(org.apache.pulsar.policies.data.loadbalancer.BrokerData) ResourceUsage(org.apache.pulsar.policies.data.loadbalancer.ResourceUsage) TimeAverageMessageData(org.apache.pulsar.policies.data.loadbalancer.TimeAverageMessageData) BundleData(org.apache.pulsar.policies.data.loadbalancer.BundleData) Test(org.testng.annotations.Test)

Example 2 with TimeAverageMessageData

use of org.apache.pulsar.policies.data.loadbalancer.TimeAverageMessageData in project pulsar by yahoo.

the class OverloadShedderTest method testBrokerWithSingleBundle.

@Test
public void testBrokerWithSingleBundle() {
    LoadData loadData = new LoadData();
    LocalBrokerData broker1 = new LocalBrokerData();
    broker1.setBandwidthIn(new ResourceUsage(999, 1000));
    broker1.setBandwidthOut(new ResourceUsage(999, 1000));
    broker1.setBundles(Sets.newHashSet("bundle-1"));
    BundleData bundle1 = new BundleData();
    TimeAverageMessageData db1 = new TimeAverageMessageData();
    db1.setMsgThroughputIn(1000);
    db1.setMsgThroughputOut(1000);
    bundle1.setShortTermData(db1);
    loadData.getBundleData().put("bundle-1", bundle1);
    loadData.getBrokerData().put("broker-1", new BrokerData(broker1));
    assertTrue(os.findBundlesForUnloading(loadData, conf).isEmpty());
}
Also used : LoadData(org.apache.pulsar.broker.loadbalance.LoadData) LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) BrokerData(org.apache.pulsar.policies.data.loadbalancer.BrokerData) ResourceUsage(org.apache.pulsar.policies.data.loadbalancer.ResourceUsage) TimeAverageMessageData(org.apache.pulsar.policies.data.loadbalancer.TimeAverageMessageData) BundleData(org.apache.pulsar.policies.data.loadbalancer.BundleData) Test(org.testng.annotations.Test)

Example 3 with TimeAverageMessageData

use of org.apache.pulsar.policies.data.loadbalancer.TimeAverageMessageData in project pulsar by yahoo.

the class OverloadShedderTest method testFilterRecentlyUnloaded.

@Test
public void testFilterRecentlyUnloaded() {
    int numBundles = 10;
    LoadData loadData = new LoadData();
    LocalBrokerData broker1 = new LocalBrokerData();
    broker1.setBandwidthIn(new ResourceUsage(999, 1000));
    broker1.setBandwidthOut(new ResourceUsage(999, 1000));
    double brokerThroghput = 0;
    for (int i = 1; i <= numBundles; i++) {
        broker1.getBundles().add("bundle-" + i);
        BundleData bundle = new BundleData();
        TimeAverageMessageData db = new TimeAverageMessageData();
        double throughput = i * 1024 * 1024;
        db.setMsgThroughputIn(throughput);
        db.setMsgThroughputOut(throughput);
        bundle.setShortTermData(db);
        loadData.getBundleData().put("bundle-" + i, bundle);
        brokerThroghput += throughput;
    }
    broker1.setMsgThroughputIn(brokerThroghput);
    broker1.setMsgThroughputOut(brokerThroghput);
    loadData.getBrokerData().put("broker-1", new BrokerData(broker1));
    loadData.getRecentlyUnloadedBundles().put("bundle-10", 1L);
    loadData.getRecentlyUnloadedBundles().put("bundle-9", 1L);
    Multimap<String, String> bundlesToUnload = os.findBundlesForUnloading(loadData, conf);
    assertFalse(bundlesToUnload.isEmpty());
    assertEquals(bundlesToUnload.get("broker-1"), Lists.newArrayList("bundle-8", "bundle-7"));
}
Also used : LoadData(org.apache.pulsar.broker.loadbalance.LoadData) LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) BrokerData(org.apache.pulsar.policies.data.loadbalancer.BrokerData) ResourceUsage(org.apache.pulsar.policies.data.loadbalancer.ResourceUsage) TimeAverageMessageData(org.apache.pulsar.policies.data.loadbalancer.TimeAverageMessageData) BundleData(org.apache.pulsar.policies.data.loadbalancer.BundleData) Test(org.testng.annotations.Test)

Example 4 with TimeAverageMessageData

use of org.apache.pulsar.policies.data.loadbalancer.TimeAverageMessageData in project pulsar by yahoo.

the class ThresholdShedderTest method testBrokerNotReachThreshold.

@Test
public void testBrokerNotReachThreshold() {
    LoadData loadData = new LoadData();
    LocalBrokerData broker1 = new LocalBrokerData();
    broker1.setBandwidthIn(new ResourceUsage(500, 1000));
    broker1.setBandwidthOut(new ResourceUsage(500, 1000));
    broker1.setBundles(Sets.newHashSet("bundle-1"));
    BundleData bundleData = new BundleData();
    TimeAverageMessageData timeAverageMessageData = new TimeAverageMessageData();
    timeAverageMessageData.setMsgThroughputIn(1000);
    timeAverageMessageData.setMsgThroughputOut(1000);
    bundleData.setShortTermData(timeAverageMessageData);
    loadData.getBundleData().put("bundle-1", bundleData);
    loadData.getBrokerData().put("broker-1", new BrokerData(broker1));
    assertTrue(thresholdShedder.findBundlesForUnloading(loadData, conf).isEmpty());
}
Also used : LoadData(org.apache.pulsar.broker.loadbalance.LoadData) LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) BrokerData(org.apache.pulsar.policies.data.loadbalancer.BrokerData) ResourceUsage(org.apache.pulsar.policies.data.loadbalancer.ResourceUsage) TimeAverageMessageData(org.apache.pulsar.policies.data.loadbalancer.TimeAverageMessageData) BundleData(org.apache.pulsar.policies.data.loadbalancer.BundleData) Test(org.testng.annotations.Test)

Example 5 with TimeAverageMessageData

use of org.apache.pulsar.policies.data.loadbalancer.TimeAverageMessageData in project pulsar by yahoo.

the class BundleSplitterTask method findBundlesToSplit.

/**
 * Determines which bundles should be split based on various thresholds.
 *
 * @param loadData
 *            Load data to base decisions on (does not have benefit of preallocated data since this may not be the
 *            leader broker).
 * @param pulsar
 *            Service to use.
 * @return All bundles who have exceeded configured thresholds in number of topics, number of sessions, total
 *         message rates, or total throughput.
 */
@Override
public Set<String> findBundlesToSplit(final LoadData loadData, final PulsarService pulsar) {
    bundleCache.clear();
    final ServiceConfiguration conf = pulsar.getConfiguration();
    int maxBundleCount = conf.getLoadBalancerNamespaceMaximumBundles();
    long maxBundleTopics = conf.getLoadBalancerNamespaceBundleMaxTopics();
    long maxBundleSessions = conf.getLoadBalancerNamespaceBundleMaxSessions();
    long maxBundleMsgRate = conf.getLoadBalancerNamespaceBundleMaxMsgRate();
    long maxBundleBandwidth = conf.getLoadBalancerNamespaceBundleMaxBandwidthMbytes() * LoadManagerShared.MIBI;
    loadData.getBrokerData().forEach((broker, brokerData) -> {
        LocalBrokerData localData = brokerData.getLocalData();
        for (final Map.Entry<String, NamespaceBundleStats> entry : localData.getLastStats().entrySet()) {
            final String bundle = entry.getKey();
            final NamespaceBundleStats stats = entry.getValue();
            if (stats.topics < 2) {
                log.info("The count of topics on the bundle {} is less than 2, skip split!", bundle);
                continue;
            }
            double totalMessageRate = 0;
            double totalMessageThroughput = 0;
            // Attempt to consider long-term message data, otherwise effectively ignore.
            if (loadData.getBundleData().containsKey(bundle)) {
                final TimeAverageMessageData longTermData = loadData.getBundleData().get(bundle).getLongTermData();
                totalMessageRate = longTermData.totalMsgRate();
                totalMessageThroughput = longTermData.totalMsgThroughput();
            }
            if (stats.topics > maxBundleTopics || (maxBundleSessions > 0 && (stats.consumerCount + stats.producerCount > maxBundleSessions)) || totalMessageRate > maxBundleMsgRate || totalMessageThroughput > maxBundleBandwidth) {
                final String namespace = LoadManagerShared.getNamespaceNameFromBundleName(bundle);
                try {
                    final int bundleCount = pulsar.getNamespaceService().getBundleCount(NamespaceName.get(namespace));
                    if (bundleCount < maxBundleCount) {
                        bundleCache.add(bundle);
                    } else {
                        if (log.isDebugEnabled()) {
                            log.debug("Could not split namespace bundle {} because namespace {} has too many bundles:" + "{}", bundle, namespace, bundleCount);
                        }
                    }
                } catch (Exception e) {
                    log.warn("Error while getting bundle count for namespace {}", namespace, e);
                }
            }
        }
    });
    return bundleCache;
}
Also used : ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) NamespaceBundleStats(org.apache.pulsar.policies.data.loadbalancer.NamespaceBundleStats) TimeAverageMessageData(org.apache.pulsar.policies.data.loadbalancer.TimeAverageMessageData) Map(java.util.Map)

Aggregations

TimeAverageMessageData (org.apache.pulsar.policies.data.loadbalancer.TimeAverageMessageData)38 BundleData (org.apache.pulsar.policies.data.loadbalancer.BundleData)36 LocalBrokerData (org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData)26 Test (org.testng.annotations.Test)26 LoadData (org.apache.pulsar.broker.loadbalance.LoadData)24 BrokerData (org.apache.pulsar.policies.data.loadbalancer.BrokerData)22 ResourceUsage (org.apache.pulsar.policies.data.loadbalancer.ResourceUsage)16 HashMap (java.util.HashMap)8 Map (java.util.Map)8 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)8 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)6 Multimap (com.google.common.collect.Multimap)6 MutableDouble (org.apache.commons.lang3.mutable.MutableDouble)6 LoadSheddingStrategy (org.apache.pulsar.broker.loadbalance.LoadSheddingStrategy)6 TimeAverageBrokerData (org.apache.pulsar.policies.data.loadbalancer.TimeAverageBrokerData)6 HashSet (java.util.HashSet)4 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)4 Pair (org.apache.commons.lang3.tuple.Pair)4 NamespaceBundle (org.apache.pulsar.common.naming.NamespaceBundle)4 NamespaceBundleStats (org.apache.pulsar.policies.data.loadbalancer.NamespaceBundleStats)4