Search in sources :

Example 1 with TimeAverageBrokerData

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

the class ModularLoadManagerStrategyTest method initBrokerData.

private BrokerData initBrokerData() {
    LocalBrokerData localBrokerData = new LocalBrokerData();
    localBrokerData.setCpu(new ResourceUsage());
    localBrokerData.setMemory(new ResourceUsage());
    localBrokerData.setBandwidthIn(new ResourceUsage());
    localBrokerData.setBandwidthOut(new ResourceUsage());
    BrokerData brokerData = new BrokerData(localBrokerData);
    TimeAverageBrokerData timeAverageBrokerData = new TimeAverageBrokerData();
    brokerData.setTimeAverageData(timeAverageBrokerData);
    return brokerData;
}
Also used : LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) BrokerData(org.apache.pulsar.policies.data.loadbalancer.BrokerData) LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) TimeAverageBrokerData(org.apache.pulsar.policies.data.loadbalancer.TimeAverageBrokerData) ResourceUsage(org.apache.pulsar.policies.data.loadbalancer.ResourceUsage) TimeAverageBrokerData(org.apache.pulsar.policies.data.loadbalancer.TimeAverageBrokerData)

Example 2 with TimeAverageBrokerData

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

the class TimeAverageBrokerDataTest method testIllegalArg.

@Test
public void testIllegalArg() {
    TimeAverageBrokerData timeAverageBrokerData = new TimeAverageBrokerData();
    assertThrows(NullPointerException.class, () -> timeAverageBrokerData.reset(null, null, null));
}
Also used : TimeAverageBrokerData(org.apache.pulsar.policies.data.loadbalancer.TimeAverageBrokerData) Test(org.testng.annotations.Test)

Example 3 with TimeAverageBrokerData

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

the class TimeAverageBrokerDataTest method testResetMethodOfOneBundlesEmptyBundleMap.

@Test
public void testResetMethodOfOneBundlesEmptyBundleMap() {
    TimeAverageBrokerData timeAverageBrokerData = new TimeAverageBrokerData();
    Set<String> bundles = new HashSet<>();
    bundles.add("a");
    Map<String, BundleData> emptyMap = new HashMap<>();
    NamespaceBundleStats namespaceBundleStats = new NamespaceBundleStats();
    namespaceBundleStats.msgThroughputIn = 1;
    namespaceBundleStats.msgThroughputOut = 2;
    namespaceBundleStats.msgRateIn = 3;
    namespaceBundleStats.msgRateOut = 4;
    timeAverageBrokerData.reset(bundles, emptyMap, namespaceBundleStats);
    assertEquals(timeAverageBrokerData.getShortTermMsgThroughputIn(), 1);
    assertEquals(timeAverageBrokerData.getShortTermMsgThroughputOut(), 2);
    assertEquals(timeAverageBrokerData.getShortTermMsgRateIn(), 3);
    assertEquals(timeAverageBrokerData.getShortTermMsgRateOut(), 4);
    assertEquals(timeAverageBrokerData.getLongTermMsgThroughputIn(), 1);
    assertEquals(timeAverageBrokerData.getLongTermMsgThroughputOut(), 2);
    assertEquals(timeAverageBrokerData.getLongTermMsgRateIn(), 3);
    assertEquals(timeAverageBrokerData.getLongTermMsgRateOut(), 4);
}
Also used : NamespaceBundleStats(org.apache.pulsar.policies.data.loadbalancer.NamespaceBundleStats) HashMap(java.util.HashMap) BundleData(org.apache.pulsar.policies.data.loadbalancer.BundleData) TimeAverageBrokerData(org.apache.pulsar.policies.data.loadbalancer.TimeAverageBrokerData) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 4 with TimeAverageBrokerData

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

the class ModularLoadManagerImpl method writeBundleDataOnZooKeeper.

/**
 * As the leader broker, write bundle data aggregated from all brokers to metadata store.
 */
@Override
public void writeBundleDataOnZooKeeper() {
    updateBundleData();
    // Write the bundle data to metadata store.
    List<CompletableFuture<Void>> futures = new ArrayList<>();
    for (Map.Entry<String, BundleData> entry : loadData.getBundleData().entrySet()) {
        final String bundle = entry.getKey();
        final BundleData data = entry.getValue();
        futures.add(bundlesCache.readModifyUpdateOrCreate(getBundleDataPath(bundle), __ -> data).thenApply(__ -> null));
    }
    // Write the time average broker data to metadata store.
    for (Map.Entry<String, BrokerData> entry : loadData.getBrokerData().entrySet()) {
        final String broker = entry.getKey();
        final TimeAverageBrokerData data = entry.getValue().getTimeAverageData();
        futures.add(timeAverageBrokerDataCache.readModifyUpdateOrCreate(TIME_AVERAGE_BROKER_ZPATH + "/" + broker, __ -> data).thenApply(__ -> null));
    }
    try {
        FutureUtil.waitForAll(futures).join();
    } catch (Exception e) {
        log.warn("Error when writing metadata data to store", e);
    }
}
Also used : Metrics(org.apache.pulsar.common.stats.Metrics) BundleData(org.apache.pulsar.policies.data.loadbalancer.BundleData) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) LoggerFactory(org.slf4j.LoggerFactory) LoadSheddingStrategy(org.apache.pulsar.broker.loadbalance.LoadSheddingStrategy) LoadManager(org.apache.pulsar.broker.loadbalance.LoadManager) ModularLoadManagerStrategy(org.apache.pulsar.broker.loadbalance.ModularLoadManagerStrategy) StringUtils(org.apache.commons.lang3.StringUtils) BundleSplitStrategy(org.apache.pulsar.broker.loadbalance.BundleSplitStrategy) Notification(org.apache.pulsar.metadata.api.Notification) MetadataCache(org.apache.pulsar.metadata.api.MetadataCache) SystemResourceUsage(org.apache.pulsar.policies.data.loadbalancer.SystemResourceUsage) Map(java.util.Map) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) BrokerHostUsage(org.apache.pulsar.broker.loadbalance.BrokerHostUsage) LoadData(org.apache.pulsar.broker.loadbalance.LoadData) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) LocalPolicies(org.apache.pulsar.common.policies.data.LocalPolicies) CompletionException(java.util.concurrent.CompletionException) ModularLoadManager(org.apache.pulsar.broker.loadbalance.ModularLoadManager) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) NamespaceBundleFactory(org.apache.pulsar.common.naming.NamespaceBundleFactory) List(java.util.List) ServiceUnitId(org.apache.pulsar.common.naming.ServiceUnitId) FutureUtil(org.apache.pulsar.common.util.FutureUtil) ConcurrentOpenHashSet(org.apache.pulsar.common.util.collections.ConcurrentOpenHashSet) ConcurrentOpenHashMap(org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap) NotFoundException(org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException) SessionEvent(org.apache.pulsar.metadata.api.extended.SessionEvent) BrokerData(org.apache.pulsar.policies.data.loadbalancer.BrokerData) Optional(java.util.Optional) NamespaceBundleStats(org.apache.pulsar.policies.data.loadbalancer.NamespaceBundleStats) ConcurrentModificationException(java.util.ConcurrentModificationException) TimeAverageBrokerData(org.apache.pulsar.policies.data.loadbalancer.TimeAverageBrokerData) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Multimap(com.google.common.collect.Multimap) AtomicReference(java.util.concurrent.atomic.AtomicReference) LockManager(org.apache.pulsar.metadata.api.coordination.LockManager) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) BrokerFilter(org.apache.pulsar.broker.loadbalance.BrokerFilter) HashSet(java.util.HashSet) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Lists(com.google.common.collect.Lists) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BrokerFilterException(org.apache.pulsar.broker.loadbalance.BrokerFilterException) ClusterResources(org.apache.pulsar.broker.resources.ClusterResources) Summary(org.apache.pulsar.broker.stats.prometheus.metrics.Summary) ResourceQuota(org.apache.pulsar.common.policies.data.ResourceQuota) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ReentrantLock(java.util.concurrent.locks.ReentrantLock) SystemUtils(org.apache.commons.lang3.SystemUtils) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) BrokerTopicLoadingPredicate(org.apache.pulsar.broker.loadbalance.impl.LoadManagerShared.BrokerTopicLoadingPredicate) PulsarService(org.apache.pulsar.broker.PulsarService) TimeAverageMessageData(org.apache.pulsar.policies.data.loadbalancer.TimeAverageMessageData) Maps(com.google.common.collect.Maps) TimeUnit(java.util.concurrent.TimeUnit) Lock(java.util.concurrent.locks.Lock) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) ResourceLock(org.apache.pulsar.metadata.api.coordination.ResourceLock) FailureDomainImpl(org.apache.pulsar.common.policies.data.FailureDomainImpl) CompletableFuture(java.util.concurrent.CompletableFuture) BrokerData(org.apache.pulsar.policies.data.loadbalancer.BrokerData) TimeAverageBrokerData(org.apache.pulsar.policies.data.loadbalancer.TimeAverageBrokerData) LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentOpenHashMap(org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap) HashMap(java.util.HashMap) BundleData(org.apache.pulsar.policies.data.loadbalancer.BundleData) TimeAverageBrokerData(org.apache.pulsar.policies.data.loadbalancer.TimeAverageBrokerData) MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) CompletionException(java.util.concurrent.CompletionException) NotFoundException(org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException) ConcurrentModificationException(java.util.ConcurrentModificationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) BrokerFilterException(org.apache.pulsar.broker.loadbalance.BrokerFilterException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) PulsarServerException(org.apache.pulsar.broker.PulsarServerException)

Example 5 with TimeAverageBrokerData

use of org.apache.pulsar.policies.data.loadbalancer.TimeAverageBrokerData in project incubator-pulsar by apache.

the class TimeAverageBrokerDataTest method testResetMethodOfOneBundlesEmptyBundleMap.

@Test
public void testResetMethodOfOneBundlesEmptyBundleMap() {
    TimeAverageBrokerData timeAverageBrokerData = new TimeAverageBrokerData();
    Set<String> bundles = new HashSet<>();
    bundles.add("a");
    Map<String, BundleData> emptyMap = new HashMap<>();
    NamespaceBundleStats namespaceBundleStats = new NamespaceBundleStats();
    namespaceBundleStats.msgThroughputIn = 1;
    namespaceBundleStats.msgThroughputOut = 2;
    namespaceBundleStats.msgRateIn = 3;
    namespaceBundleStats.msgRateOut = 4;
    timeAverageBrokerData.reset(bundles, emptyMap, namespaceBundleStats);
    assertEquals(timeAverageBrokerData.getShortTermMsgThroughputIn(), 1);
    assertEquals(timeAverageBrokerData.getShortTermMsgThroughputOut(), 2);
    assertEquals(timeAverageBrokerData.getShortTermMsgRateIn(), 3);
    assertEquals(timeAverageBrokerData.getShortTermMsgRateOut(), 4);
    assertEquals(timeAverageBrokerData.getLongTermMsgThroughputIn(), 1);
    assertEquals(timeAverageBrokerData.getLongTermMsgThroughputOut(), 2);
    assertEquals(timeAverageBrokerData.getLongTermMsgRateIn(), 3);
    assertEquals(timeAverageBrokerData.getLongTermMsgRateOut(), 4);
}
Also used : NamespaceBundleStats(org.apache.pulsar.policies.data.loadbalancer.NamespaceBundleStats) HashMap(java.util.HashMap) BundleData(org.apache.pulsar.policies.data.loadbalancer.BundleData) TimeAverageBrokerData(org.apache.pulsar.policies.data.loadbalancer.TimeAverageBrokerData) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

TimeAverageBrokerData (org.apache.pulsar.policies.data.loadbalancer.TimeAverageBrokerData)20 BundleData (org.apache.pulsar.policies.data.loadbalancer.BundleData)14 HashMap (java.util.HashMap)12 HashSet (java.util.HashSet)12 TimeAverageMessageData (org.apache.pulsar.policies.data.loadbalancer.TimeAverageMessageData)10 Test (org.testng.annotations.Test)10 LocalBrokerData (org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData)8 NamespaceBundleStats (org.apache.pulsar.policies.data.loadbalancer.NamespaceBundleStats)8 Map (java.util.Map)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 BrokerData (org.apache.pulsar.policies.data.loadbalancer.BrokerData)6 SystemResourceUsage (org.apache.pulsar.policies.data.loadbalancer.SystemResourceUsage)6 Lists (com.google.common.collect.Lists)4 Maps (com.google.common.collect.Maps)4 Multimap (com.google.common.collect.Multimap)4 Sets (com.google.common.collect.Sets)4 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)4 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 ConcurrentModificationException (java.util.ConcurrentModificationException)4