Search in sources :

Example 6 with ObjectResourcesSummary

use of org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesSummary in project storm by apache.

the class NodeSorterHostProximity method createClusterSummarizedResources.

private ObjectResourcesSummary createClusterSummarizedResources() {
    ObjectResourcesSummary clusterResourcesSummary = new ObjectResourcesSummary("Cluster");
    rackIdToHosts.forEach((rackId, hostIds) -> {
        if (hostIds == null || hostIds.isEmpty()) {
            LOG.info("Ignoring Rack {} since it has no hosts", rackId);
        } else {
            ObjectResourcesItem rack = new ObjectResourcesItem(rackId);
            for (String hostId : hostIds) {
                for (RasNode node : hostnameToNodes(hostId)) {
                    rack.availableResources.add(node.getTotalAvailableResources());
                    rack.totalResources.add(node.getTotalResources());
                }
            }
            clusterResourcesSummary.addObjectResourcesItem(rack);
        }
    });
    LOG.debug("Cluster Overall Avail [ {} ] Total [ {} ], rackCnt={}, hostCnt={}", clusterResourcesSummary.getAvailableResourcesOverall(), clusterResourcesSummary.getTotalResourcesOverall(), clusterResourcesSummary.getObjectResources().size(), rackIdToHosts.values().stream().mapToInt(x -> x.size()).sum());
    return clusterResourcesSummary;
}
Also used : ObjectResourcesSummary(org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesSummary) ObjectResourcesItem(org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesItem) RasNode(org.apache.storm.scheduler.resource.RasNode)

Example 7 with ObjectResourcesSummary

use of org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesSummary in project storm by apache.

the class NodeSorterHostProximity method sortHosts.

/**
 * Nodes are sorted by two criteria.
 *
 * <p>1) the number executors of the topology that needs to be scheduled is already on the node in
 * descending order. The reasoning to sort based on criterion 1 is so we schedule the rest of a topology on the same node as the
 * existing executors of the topology.
 *
 * <p>2) the subordinate/subservient resource availability percentage of a node in descending
 * order We calculate the resource availability percentage by dividing the resource availability that have exhausted or little of one of
 * the resources mentioned above will be ranked after on the node by the resource availability of the entire rack By doing this
 * calculation, nodes nodes that have more balanced resource availability. So we will be less likely to pick a node that have a lot of
 * one resource but a low amount of another.
 *
 * @param availHosts a collection of all the hosts we want to sort
 * @param rackId     the rack id availNodes are a part of
 * @return an iterable of sorted hosts.
 */
private Iterable<ObjectResourcesItem> sortHosts(Collection<String> availHosts, ExecutorDetails exec, String rackId, Map<String, AtomicInteger> scheduledCount) {
    ObjectResourcesSummary rackResourcesSummary = new ObjectResourcesSummary("RACK");
    availHosts.forEach(h -> {
        ObjectResourcesItem hostItem = new ObjectResourcesItem(h);
        for (RasNode x : hostnameToNodes.get(h)) {
            hostItem.add(new ObjectResourcesItem(x.getId(), x.getTotalAvailableResources(), x.getTotalResources(), 0, 0));
        }
        rackResourcesSummary.addObjectResourcesItem(hostItem);
    });
    LOG.debug("Rack {}: Overall Avail [ {} ] Total [ {} ]", rackId, rackResourcesSummary.getAvailableResourcesOverall(), rackResourcesSummary.getTotalResourcesOverall());
    return sortObjectResources(rackResourcesSummary, exec, (hostId) -> {
        AtomicInteger count = scheduledCount.get(hostId);
        if (count == null) {
            return 0;
        }
        return count.get();
    });
}
Also used : ObjectResourcesSummary(org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesSummary) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ObjectResourcesItem(org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesItem) RasNode(org.apache.storm.scheduler.resource.RasNode)

Example 8 with ObjectResourcesSummary

use of org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesSummary in project storm by apache.

the class NodeSorterHostProximity method sortObjectResourcesGeneric.

/**
 * Sort objects by the following two criteria.
 *
 * <li>the number executors of the topology that needs to be scheduled is already on the
 * object (node or rack) in descending order. The reasoning to sort based on criterion 1 is so we schedule the rest
 * of a topology on the same object (node or rack) as the existing executors of the topology.</li>
 *
 * <li>the subordinate/subservient resource availability percentage of a rack in descending order We calculate the
 * resource availability percentage by dividing the resource availability of the object (node or rack) by the
 * resource availability of the entire rack or cluster depending on if object references a node or a rack.
 * How this differs from the DefaultResourceAwareStrategy is that the percentage boosts the node or rack if it is
 * requested by the executor that the sorting is being done for and pulls it down if it is not.
 * By doing this calculation, objects (node or rack) that have exhausted or little of one of the resources mentioned
 * above will be ranked after racks that have more balanced resource availability and nodes or racks that have
 * resources that are not requested will be ranked below . So we will be less likely to pick a rack that
 * have a lot of one resource but a low amount of another and have a lot of resources that are not requested by the executor.</li>
 *
 * @param allResources         contains all individual ObjectResources as well as cumulative stats
 * @param exec                 executor for which the sorting is done
 * @param existingScheduleFunc a function to get existing executors already scheduled on this object
 * @return an {@link Iterable} of sorted {@link ObjectResourcesItem}
 */
@Deprecated
private Iterable<ObjectResourcesItem> sortObjectResourcesGeneric(final ObjectResourcesSummary allResources, ExecutorDetails exec, final ExistingScheduleFunc existingScheduleFunc) {
    ObjectResourcesSummary affinityBasedAllResources = new ObjectResourcesSummary(allResources);
    final NormalizedResourceOffer availableResourcesOverall = allResources.getAvailableResourcesOverall();
    final NormalizedResourceRequest requestedResources = (exec != null) ? topologyDetails.getTotalResources(exec) : null;
    affinityBasedAllResources.getObjectResources().forEach(x -> {
        if (requestedResources != null) {
            // negate unrequested resources
            x.availableResources.updateForRareResourceAffinity(requestedResources);
        }
        x.minResourcePercent = availableResourcesOverall.calculateMinPercentageUsedBy(x.availableResources);
        x.avgResourcePercent = availableResourcesOverall.calculateAveragePercentageUsedBy(x.availableResources);
        LOG.trace("for {}: minResourcePercent={}, avgResourcePercent={}, numExistingSchedule={}", x.id, x.minResourcePercent, x.avgResourcePercent, existingScheduleFunc.getNumExistingSchedule(x.id));
    });
    Comparator<ObjectResourcesItem> comparator = (o1, o2) -> {
        int execsScheduled1 = existingScheduleFunc.getNumExistingSchedule(o1.id);
        int execsScheduled2 = existingScheduleFunc.getNumExistingSchedule(o2.id);
        if (execsScheduled1 > execsScheduled2) {
            return -1;
        } else if (execsScheduled1 < execsScheduled2) {
            return 1;
        }
        double o1Avg = o1.avgResourcePercent;
        double o2Avg = o2.avgResourcePercent;
        if (o1Avg > o2Avg) {
            return -1;
        } else if (o1Avg < o2Avg) {
            return 1;
        }
        return o1.id.compareTo(o2.id);
    };
    TreeSet<ObjectResourcesItem> sortedObjectResources = new TreeSet<>(comparator);
    sortedObjectResources.addAll(affinityBasedAllResources.getObjectResources());
    LOG.debug("Sorted Object Resources: {}", sortedObjectResources);
    return sortedObjectResources;
}
Also used : NormalizedResourceOffer(org.apache.storm.scheduler.resource.normalization.NormalizedResourceOffer) NormalizedResourceRequest(org.apache.storm.scheduler.resource.normalization.NormalizedResourceRequest) RasNode(org.apache.storm.scheduler.resource.RasNode) LoggerFactory(org.slf4j.LoggerFactory) NormalizedResourceOffer(org.apache.storm.scheduler.resource.normalization.NormalizedResourceOffer) HashMap(java.util.HashMap) RasNodes(org.apache.storm.scheduler.resource.RasNodes) BaseResourceAwareStrategy(org.apache.storm.scheduler.resource.strategies.scheduling.BaseResourceAwareStrategy) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) VisibleForTesting(org.apache.storm.shade.com.google.common.annotations.VisibleForTesting) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) NoSuchElementException(java.util.NoSuchElementException) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) DNSToSwitchMapping(org.apache.storm.networktopography.DNSToSwitchMapping) ObjectResourcesSummary(org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesSummary) Collection(java.util.Collection) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) Set(java.util.Set) Collectors(java.util.stream.Collectors) Cluster(org.apache.storm.scheduler.Cluster) List(java.util.List) Stream(java.util.stream.Stream) ObjectResourcesItem(org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesItem) Config(org.apache.storm.Config) Comparator(java.util.Comparator) Collections(java.util.Collections) ExecutorDetails(org.apache.storm.scheduler.ExecutorDetails) ObjectResourcesSummary(org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesSummary) NormalizedResourceRequest(org.apache.storm.scheduler.resource.normalization.NormalizedResourceRequest) TreeSet(java.util.TreeSet) ObjectResourcesItem(org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesItem)

Example 9 with ObjectResourcesSummary

use of org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesSummary in project storm by apache.

the class NodeSorterHostProximity method sortObjectResourcesDefault.

/**
 * Sort objects by the following two criteria.
 *
 * <li>the number executors of the topology that needs to be scheduled is already on the
 * object (node or rack) in descending order. The reasoning to sort based on criterion 1 is so we schedule the rest
 * of a topology on the same object (node or rack) as the existing executors of the topology.</li>
 *
 * <li>the subordinate/subservient resource availability percentage of a rack in descending order We calculate the
 * resource availability percentage by dividing the resource availability of the object (node or rack) by the
 * resource availability of the entire rack or cluster depending on if object references a node or a rack.
 * By doing this calculation, objects (node or rack) that have exhausted or little of one of the resources mentioned
 * above will be ranked after racks that have more balanced resource availability. So we will be less likely to pick
 * a rack that have a lot of one resource but a low amount of another.</li>
 *
 * @param allResources         contains all individual ObjectResources as well as cumulative stats
 * @param existingScheduleFunc a function to get existing executors already scheduled on this object
 * @return an {@link Iterable} of sorted {@link ObjectResourcesItem}
 */
@Deprecated
private Iterable<ObjectResourcesItem> sortObjectResourcesDefault(final ObjectResourcesSummary allResources, final ExistingScheduleFunc existingScheduleFunc) {
    final NormalizedResourceOffer availableResourcesOverall = allResources.getAvailableResourcesOverall();
    for (ObjectResourcesItem objectResources : allResources.getObjectResources()) {
        objectResources.minResourcePercent = availableResourcesOverall.calculateMinPercentageUsedBy(objectResources.availableResources);
        objectResources.avgResourcePercent = availableResourcesOverall.calculateAveragePercentageUsedBy(objectResources.availableResources);
        LOG.trace("for {}: minResourcePercent={}, avgResourcePercent={}, numExistingSchedule={}", objectResources.id, objectResources.minResourcePercent, objectResources.avgResourcePercent, existingScheduleFunc.getNumExistingSchedule(objectResources.id));
    }
    Comparator<ObjectResourcesItem> comparator = (o1, o2) -> {
        int execsScheduled1 = existingScheduleFunc.getNumExistingSchedule(o1.id);
        int execsScheduled2 = existingScheduleFunc.getNumExistingSchedule(o2.id);
        if (execsScheduled1 > execsScheduled2) {
            return -1;
        } else if (execsScheduled1 < execsScheduled2) {
            return 1;
        }
        if (o1.minResourcePercent > o2.minResourcePercent) {
            return -1;
        } else if (o1.minResourcePercent < o2.minResourcePercent) {
            return 1;
        }
        double diff = o1.avgResourcePercent - o2.avgResourcePercent;
        if (diff > 0.0) {
            return -1;
        } else if (diff < 0.0) {
            return 1;
        }
        return o1.id.compareTo(o2.id);
    };
    TreeSet<ObjectResourcesItem> sortedObjectResources = new TreeSet<>(comparator);
    sortedObjectResources.addAll(allResources.getObjectResources());
    LOG.debug("Sorted Object Resources: {}", sortedObjectResources);
    return sortedObjectResources;
}
Also used : NormalizedResourceOffer(org.apache.storm.scheduler.resource.normalization.NormalizedResourceOffer) NormalizedResourceRequest(org.apache.storm.scheduler.resource.normalization.NormalizedResourceRequest) RasNode(org.apache.storm.scheduler.resource.RasNode) LoggerFactory(org.slf4j.LoggerFactory) NormalizedResourceOffer(org.apache.storm.scheduler.resource.normalization.NormalizedResourceOffer) HashMap(java.util.HashMap) RasNodes(org.apache.storm.scheduler.resource.RasNodes) BaseResourceAwareStrategy(org.apache.storm.scheduler.resource.strategies.scheduling.BaseResourceAwareStrategy) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) VisibleForTesting(org.apache.storm.shade.com.google.common.annotations.VisibleForTesting) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) NoSuchElementException(java.util.NoSuchElementException) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) DNSToSwitchMapping(org.apache.storm.networktopography.DNSToSwitchMapping) ObjectResourcesSummary(org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesSummary) Collection(java.util.Collection) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) Set(java.util.Set) Collectors(java.util.stream.Collectors) Cluster(org.apache.storm.scheduler.Cluster) List(java.util.List) Stream(java.util.stream.Stream) ObjectResourcesItem(org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesItem) Config(org.apache.storm.Config) Comparator(java.util.Comparator) Collections(java.util.Collections) ExecutorDetails(org.apache.storm.scheduler.ExecutorDetails) TreeSet(java.util.TreeSet) ObjectResourcesItem(org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesItem)

Example 10 with ObjectResourcesSummary

use of org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesSummary in project storm by apache.

the class NodeSorterHostProximity method getSortedRacks.

/**
 * Racks are sorted by two criteria.
 *
 * <p>1) the number executors of the topology that needs to be scheduled is already on the rack in descending order.
 * The reasoning to sort based on criterion 1 is so we schedule the rest of a topology on the same rack as the existing executors of the
 * topology.
 *
 * <p>2) the subordinate/subservient resource availability percentage of a rack in descending order We calculate
 * the resource availability percentage by dividing the resource availability on the rack by the resource availability of the  entire
 * cluster By doing this calculation, racks that have exhausted or little of one of the resources mentioned above will be ranked after
 * racks that have more balanced resource availability. So we will be less likely to pick a rack that have a lot of one resource but a
 * low amount of another.
 *
 * @return an iterable of sorted racks
 */
public Iterable<ObjectResourcesItem> getSortedRacks() {
    final ObjectResourcesSummary clusterResourcesSummary = createClusterSummarizedResources();
    final Map<String, AtomicInteger> scheduledCount = getScheduledExecCntByRackId();
    return sortObjectResources(clusterResourcesSummary, exec, (rackId) -> {
        AtomicInteger count = scheduledCount.get(rackId);
        if (count == null) {
            return 0;
        }
        return count.get();
    });
}
Also used : ObjectResourcesSummary(org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesSummary) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

ObjectResourcesSummary (org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesSummary)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 ObjectResourcesItem (org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesItem)11 RasNode (org.apache.storm.scheduler.resource.RasNode)9 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 List (java.util.List)7 Map (java.util.Map)7 Collection (java.util.Collection)6 Collections (java.util.Collections)6 Comparator (java.util.Comparator)6 HashSet (java.util.HashSet)6 Iterator (java.util.Iterator)6 NoSuchElementException (java.util.NoSuchElementException)6 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 Stream (java.util.stream.Stream)6 Config (org.apache.storm.Config)6 DNSToSwitchMapping (org.apache.storm.networktopography.DNSToSwitchMapping)6 Cluster (org.apache.storm.scheduler.Cluster)6