Search in sources :

Example 1 with ResourceType

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

the class LoadReport method getBottleneckResourceType.

@JsonIgnore
public ResourceType getBottleneckResourceType() {
    ResourceType type = ResourceType.CPU;
    double maxUsage = systemResourceUsage.cpu.percentUsage();
    if (systemResourceUsage.memory.percentUsage() > maxUsage) {
        maxUsage = systemResourceUsage.memory.percentUsage();
        type = ResourceType.Memory;
    }
    if (systemResourceUsage.bandwidthIn.percentUsage() > maxUsage) {
        maxUsage = systemResourceUsage.bandwidthIn.percentUsage();
        type = ResourceType.BandwidthIn;
    }
    if (systemResourceUsage.bandwidthOut.percentUsage() > maxUsage) {
        maxUsage = systemResourceUsage.bandwidthOut.percentUsage();
        type = ResourceType.BandwidthOut;
    }
    return type;
}
Also used : ResourceType(org.apache.pulsar.policies.data.loadbalancer.SystemResourceUsage.ResourceType) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Example 2 with ResourceType

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

the class SimpleLoadManagerImpl method doLoadShedding.

@Override
public void doLoadShedding() {
    long overloadThreshold = this.getLoadBalancerBrokerOverloadedThresholdPercentage();
    long comfortLoadLevel = this.getLoadBalancerBrokerComfortLoadThresholdPercentage();
    log.info("Running load shedding task as leader broker, overload threshold {}, comfort loadlevel {}", overloadThreshold, comfortLoadLevel);
    // overloadedRU --> bundleName
    Map<ResourceUnit, String> namespaceBundlesToBeUnloaded = new HashMap<>();
    synchronized (currentLoadReports) {
        for (Map.Entry<ResourceUnit, LoadReport> entry : currentLoadReports.entrySet()) {
            ResourceUnit overloadedRU = entry.getKey();
            LoadReport lr = entry.getValue();
            if (isAboveLoadLevel(lr.getSystemResourceUsage(), overloadThreshold)) {
                ResourceType bottleneckResourceType = lr.getBottleneckResourceType();
                Map<String, NamespaceBundleStats> bundleStats = lr.getSortedBundleStats(bottleneckResourceType);
                if (bundleStats == null) {
                    log.warn("Null bundle stats for bundle {}", lr.getName());
                    continue;
                }
                // 1. owns only one namespace
                if (bundleStats.size() == 1) {
                    // can't unload one namespace, just issue a warning message
                    String bundleName = lr.getBundleStats().keySet().iterator().next();
                    log.warn("HIGH USAGE WARNING : Sole namespace bundle {} is overloading broker {}. " + "No Load Shedding will be done on this broker", bundleName, overloadedRU.getResourceId());
                    continue;
                }
                for (Map.Entry<String, NamespaceBundleStats> bundleStat : bundleStats.entrySet()) {
                    String bundleName = bundleStat.getKey();
                    NamespaceBundleStats stats = bundleStat.getValue();
                    // We need at least one underloaded RU from list of candidates that can host this bundle
                    if (isBrokerAvailableForRebalancing(bundleStat.getKey(), comfortLoadLevel)) {
                        log.info("Namespace bundle {} will be unloaded from overloaded broker {}, bundle stats (topics: {}, producers {}, " + "consumers {}, bandwidthIn {}, bandwidthOut {})", bundleName, overloadedRU.getResourceId(), stats.topics, stats.producerCount, stats.consumerCount, stats.msgThroughputIn, stats.msgThroughputOut);
                        namespaceBundlesToBeUnloaded.put(overloadedRU, bundleName);
                    } else {
                        log.info("Unable to shed load from broker {}, no brokers with enough capacity available " + "for re-balancing {}", overloadedRU.getResourceId(), bundleName);
                    }
                    break;
                }
            }
        }
    }
    unloadNamespacesFromOverLoadedBrokers(namespaceBundlesToBeUnloaded);
}
Also used : ResourceUnit(org.apache.pulsar.broker.loadbalance.ResourceUnit) NamespaceBundleStats(org.apache.pulsar.policies.data.loadbalancer.NamespaceBundleStats) HashMap(java.util.HashMap) LoadReport(org.apache.pulsar.policies.data.loadbalancer.LoadReport) ResourceType(org.apache.pulsar.policies.data.loadbalancer.SystemResourceUsage.ResourceType) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Aggregations

ResourceType (org.apache.pulsar.policies.data.loadbalancer.SystemResourceUsage.ResourceType)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ResourceUnit (org.apache.pulsar.broker.loadbalance.ResourceUnit)1 LoadReport (org.apache.pulsar.policies.data.loadbalancer.LoadReport)1 NamespaceBundleStats (org.apache.pulsar.policies.data.loadbalancer.NamespaceBundleStats)1