Search in sources :

Example 1 with RAS_Node

use of org.apache.storm.scheduler.resource.RAS_Node in project storm by apache.

the class DefaultResourceAwareStrategy method sortRacks.

/**
     * Sort racks
     *
     * @param topoId                topology id
     * @param scheduleAssignmentMap calculated assignments so far
     * @return a sorted list of racks
     * Racks are sorted by two criteria. 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.
     * 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.
     */
TreeSet<ObjectResources> sortRacks(final String topoId, final Map<WorkerSlot, Collection<ExecutorDetails>> scheduleAssignmentMap) {
    AllResources allResources = new AllResources("Cluster");
    List<ObjectResources> racks = allResources.objectResources;
    final Map<String, String> nodeIdToRackId = new HashMap<String, String>();
    for (Map.Entry<String, List<String>> entry : _clusterInfo.entrySet()) {
        String rackId = entry.getKey();
        List<String> nodeIds = entry.getValue();
        ObjectResources rack = new ObjectResources(rackId);
        racks.add(rack);
        for (String nodeId : nodeIds) {
            RAS_Node node = _nodes.getNodeById(this.NodeHostnameToId(nodeId));
            double availMem = node.getAvailableMemoryResources();
            double availCpu = node.getAvailableCpuResources();
            double totalMem = node.getTotalMemoryResources();
            double totalCpu = node.getTotalCpuResources();
            rack.availMem += availMem;
            rack.totalMem += totalMem;
            rack.availCpu += availCpu;
            rack.totalCpu += totalCpu;
            nodeIdToRackId.put(nodeId, rack.id);
            allResources.availMemResourcesOverall += availMem;
            allResources.availCpuResourcesOverall += availCpu;
            allResources.totalMemResourcesOverall += totalMem;
            allResources.totalCpuResourcesOverall += totalCpu;
        }
    }
    LOG.debug("Cluster Overall Avail [ CPU {} MEM {} ] Total [ CPU {} MEM {} ]", allResources.availCpuResourcesOverall, allResources.availMemResourcesOverall, allResources.totalCpuResourcesOverall, allResources.totalMemResourcesOverall);
    return sortObjectResources(allResources, new ExistingScheduleFunc() {

        @Override
        public int getNumExistingSchedule(String objectId) {
            String rackId = objectId;
            //Get execs already assigned in rack
            Collection<ExecutorDetails> execs = new LinkedList<ExecutorDetails>();
            if (_cluster.getAssignmentById(topoId) != null) {
                for (Map.Entry<ExecutorDetails, WorkerSlot> entry : _cluster.getAssignmentById(topoId).getExecutorToSlot().entrySet()) {
                    String nodeId = entry.getValue().getNodeId();
                    String hostname = idToNode(nodeId).getHostname();
                    ExecutorDetails exec = entry.getKey();
                    if (nodeIdToRackId.get(hostname) != null && nodeIdToRackId.get(hostname).equals(rackId)) {
                        execs.add(exec);
                    }
                }
            }
            // get execs already scheduled in the current scheduling
            for (Map.Entry<WorkerSlot, Collection<ExecutorDetails>> entry : scheduleAssignmentMap.entrySet()) {
                WorkerSlot workerSlot = entry.getKey();
                String nodeId = workerSlot.getNodeId();
                String hostname = idToNode(nodeId).getHostname();
                if (nodeIdToRackId.get(hostname).equals(rackId)) {
                    execs.addAll(entry.getValue());
                }
            }
            return execs.size();
        }
    });
}
Also used : ExecutorDetails(org.apache.storm.scheduler.ExecutorDetails) HashMap(java.util.HashMap) RAS_Node(org.apache.storm.scheduler.resource.RAS_Node) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) Collection(java.util.Collection) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with RAS_Node

use of org.apache.storm.scheduler.resource.RAS_Node in project storm by apache.

the class TestDefaultResourceAwareStrategy method testMultipleRacks.

/**
     * Test whether strategy will choose correct rack
     */
@Test
public void testMultipleRacks() {
    final Map<String, SupervisorDetails> supMap = new HashMap<String, SupervisorDetails>();
    Map<String, Number> resourceMap = new HashMap<String, Number>();
    //generate a rack of supervisors
    resourceMap.put(Config.SUPERVISOR_CPU_CAPACITY, 400.0);
    resourceMap.put(Config.SUPERVISOR_MEMORY_CAPACITY_MB, 8000.0);
    final Map<String, SupervisorDetails> supMapRack1 = TestUtilsForResourceAwareScheduler.genSupervisors(10, 4, 0, resourceMap);
    //generate another rack of supervisors with less resources
    resourceMap.put(Config.SUPERVISOR_CPU_CAPACITY, 200.0);
    resourceMap.put(Config.SUPERVISOR_MEMORY_CAPACITY_MB, 4000.0);
    final Map<String, SupervisorDetails> supMapRack2 = TestUtilsForResourceAwareScheduler.genSupervisors(10, 4, 10, resourceMap);
    //generate some supervisors that are depleted of one resource
    resourceMap.put(Config.SUPERVISOR_CPU_CAPACITY, 0.0);
    resourceMap.put(Config.SUPERVISOR_MEMORY_CAPACITY_MB, 8000.0);
    final Map<String, SupervisorDetails> supMapRack3 = TestUtilsForResourceAwareScheduler.genSupervisors(10, 4, 20, resourceMap);
    //generate some that has alot of memory but little of cpu
    resourceMap.put(Config.SUPERVISOR_CPU_CAPACITY, 10.0);
    resourceMap.put(Config.SUPERVISOR_MEMORY_CAPACITY_MB, 8000.0 * 2 + 4000.0);
    final Map<String, SupervisorDetails> supMapRack4 = TestUtilsForResourceAwareScheduler.genSupervisors(10, 4, 30, resourceMap);
    //generate some that has alot of cpu but little of memory
    resourceMap.put(Config.SUPERVISOR_CPU_CAPACITY, 400.0 + 200.0 + 10.0);
    resourceMap.put(Config.SUPERVISOR_MEMORY_CAPACITY_MB, 1000.0);
    final Map<String, SupervisorDetails> supMapRack5 = TestUtilsForResourceAwareScheduler.genSupervisors(10, 4, 40, resourceMap);
    supMap.putAll(supMapRack1);
    supMap.putAll(supMapRack2);
    supMap.putAll(supMapRack3);
    supMap.putAll(supMapRack4);
    supMap.putAll(supMapRack5);
    Config config = new Config();
    config.putAll(Utils.readDefaultConfig());
    config.put(Config.RESOURCE_AWARE_SCHEDULER_EVICTION_STRATEGY, org.apache.storm.scheduler.resource.strategies.eviction.DefaultEvictionStrategy.class.getName());
    config.put(Config.RESOURCE_AWARE_SCHEDULER_PRIORITY_STRATEGY, org.apache.storm.scheduler.resource.strategies.priority.DefaultSchedulingPriorityStrategy.class.getName());
    config.put(Config.TOPOLOGY_SCHEDULER_STRATEGY, org.apache.storm.scheduler.resource.strategies.scheduling.DefaultResourceAwareStrategy.class.getName());
    config.put(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT, 100.0);
    config.put(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB, 500);
    config.put(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB, 500);
    config.put(Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB, Double.MAX_VALUE);
    INimbus iNimbus = new TestUtilsForResourceAwareScheduler.INimbusTest();
    Cluster cluster = new Cluster(iNimbus, supMap, new HashMap<String, SchedulerAssignmentImpl>(), config);
    //create test DNSToSwitchMapping plugin
    DNSToSwitchMapping TestNetworkTopographyPlugin = new DNSToSwitchMapping() {

        @Override
        public Map<String, String> resolve(List<String> names) {
            Map<String, String> ret = new HashMap<String, String>();
            for (SupervisorDetails sup : supMapRack1.values()) {
                ret.put(sup.getHost(), "rack-0");
            }
            for (SupervisorDetails sup : supMapRack2.values()) {
                ret.put(sup.getHost(), "rack-1");
            }
            for (SupervisorDetails sup : supMapRack3.values()) {
                ret.put(sup.getHost(), "rack-2");
            }
            for (SupervisorDetails sup : supMapRack4.values()) {
                ret.put(sup.getHost(), "rack-3");
            }
            for (SupervisorDetails sup : supMapRack5.values()) {
                ret.put(sup.getHost(), "rack-4");
            }
            return ret;
        }
    };
    List<String> supHostnames = new LinkedList<>();
    for (SupervisorDetails sup : supMap.values()) {
        supHostnames.add(sup.getHost());
    }
    Map<String, List<String>> rackToNodes = new HashMap<>();
    Map<String, String> resolvedSuperVisors = TestNetworkTopographyPlugin.resolve(supHostnames);
    for (Map.Entry<String, String> entry : resolvedSuperVisors.entrySet()) {
        String hostName = entry.getKey();
        String rack = entry.getValue();
        List<String> nodesForRack = rackToNodes.get(rack);
        if (nodesForRack == null) {
            nodesForRack = new ArrayList<String>();
            rackToNodes.put(rack, nodesForRack);
        }
        nodesForRack.add(hostName);
    }
    cluster.setNetworkTopography(rackToNodes);
    //generate topologies
    Map<String, TopologyDetails> topoMap = new HashMap<String, TopologyDetails>();
    TopologyDetails topo1 = TestUtilsForResourceAwareScheduler.getTopology("topo-1", config, 8, 0, 2, 0, currentTime - 2, 10);
    TopologyDetails topo2 = TestUtilsForResourceAwareScheduler.getTopology("topo-2", config, 8, 0, 2, 0, currentTime - 2, 10);
    topoMap.put(topo1.getId(), topo1);
    Topologies topologies = new Topologies(topoMap);
    DefaultResourceAwareStrategy rs = new DefaultResourceAwareStrategy();
    rs.prepare(new SchedulingState(new HashMap<String, User>(), cluster, topologies, config));
    TreeSet<ObjectResources> sortedRacks = rs.sortRacks(topo1.getId(), new HashMap<WorkerSlot, Collection<ExecutorDetails>>());
    Assert.assertEquals("# of racks sorted", 5, sortedRacks.size());
    Iterator<ObjectResources> it = sortedRacks.iterator();
    // Ranked first since rack-0 has the most balanced set of resources
    Assert.assertEquals("rack-0 should be ordered first", "rack-0", it.next().id);
    // Ranked second since rack-1 has a balanced set of resources but less than rack-0
    Assert.assertEquals("rack-1 should be ordered second", "rack-1", it.next().id);
    // Ranked third since rack-4 has a lot of cpu but not a lot of memory
    Assert.assertEquals("rack-4 should be ordered third", "rack-4", it.next().id);
    // Ranked fourth since rack-3 has alot of memory but not cpu
    Assert.assertEquals("rack-3 should be ordered fourth", "rack-3", it.next().id);
    //Ranked last since rack-2 has not cpu resources
    Assert.assertEquals("rack-2 should be ordered fifth", "rack-2", it.next().id);
    SchedulingResult schedulingResult = rs.schedule(topo1);
    for (Map.Entry<WorkerSlot, Collection<ExecutorDetails>> entry : schedulingResult.getSchedulingResultMap().entrySet()) {
        WorkerSlot ws = entry.getKey();
        Collection<ExecutorDetails> execs = entry.getValue();
        //make sure all workers on scheduled in rack-0
        Assert.assertEquals("assert worker scheduled on rack-0", "rack-0", resolvedSuperVisors.get(rs.idToNode(ws.getNodeId()).getHostname()));
        // make actual assignments
        cluster.assign(ws, topo1.getId(), execs);
    }
    Assert.assertEquals("All executors in topo-1 scheduled", 0, cluster.getUnassignedExecutors(topo1).size());
    //Test if topology is already partially scheduled on one rack
    topoMap.put(topo2.getId(), topo2);
    topologies = new Topologies(topoMap);
    RAS_Nodes nodes = new RAS_Nodes(cluster, topologies);
    Iterator<ExecutorDetails> executorIterator = topo2.getExecutors().iterator();
    List<String> nodeHostnames = rackToNodes.get("rack-1");
    for (int i = 0; i < topo2.getExecutors().size() / 2; i++) {
        String nodeHostname = nodeHostnames.get(i % nodeHostnames.size());
        RAS_Node node = rs.idToNode(rs.NodeHostnameToId(nodeHostname));
        WorkerSlot targetSlot = node.getFreeSlots().iterator().next();
        ExecutorDetails targetExec = executorIterator.next();
        // to keep track of free slots
        node.assign(targetSlot, topo2, Arrays.asList(targetExec));
        // to actually assign
        cluster.assign(targetSlot, topo2.getId(), Arrays.asList(targetExec));
    }
    rs = new DefaultResourceAwareStrategy();
    rs.prepare(new SchedulingState(new HashMap<String, User>(), cluster, topologies, config));
    // schedule topo2
    schedulingResult = rs.schedule(topo2);
    // checking assignments
    for (Map.Entry<WorkerSlot, Collection<ExecutorDetails>> entry : schedulingResult.getSchedulingResultMap().entrySet()) {
        WorkerSlot ws = entry.getKey();
        Collection<ExecutorDetails> execs = entry.getValue();
        //make sure all workers on scheduled in rack-1
        Assert.assertEquals("assert worker scheduled on rack-1", "rack-1", resolvedSuperVisors.get(rs.idToNode(ws.getNodeId()).getHostname()));
        // make actual assignments
        cluster.assign(ws, topo2.getId(), execs);
    }
    Assert.assertEquals("All executors in topo-2 scheduled", 0, cluster.getUnassignedExecutors(topo1).size());
}
Also used : ExecutorDetails(org.apache.storm.scheduler.ExecutorDetails) HashMap(java.util.HashMap) Config(org.apache.storm.Config) SchedulingResult(org.apache.storm.scheduler.resource.SchedulingResult) RAS_Nodes(org.apache.storm.scheduler.resource.RAS_Nodes) SchedulerAssignmentImpl(org.apache.storm.scheduler.SchedulerAssignmentImpl) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) DNSToSwitchMapping(org.apache.storm.networktopography.DNSToSwitchMapping) Topologies(org.apache.storm.scheduler.Topologies) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) Cluster(org.apache.storm.scheduler.Cluster) RAS_Node(org.apache.storm.scheduler.resource.RAS_Node) INimbus(org.apache.storm.scheduler.INimbus) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) ObjectResources(org.apache.storm.scheduler.resource.strategies.scheduling.DefaultResourceAwareStrategy.ObjectResources) LinkedList(java.util.LinkedList) SchedulingState(org.apache.storm.scheduler.resource.SchedulingState) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with RAS_Node

use of org.apache.storm.scheduler.resource.RAS_Node in project storm by apache.

the class DefaultResourceAwareStrategy method getBestWorker.

/**
     * Get the best worker to assign executor exec on a rack
     *
     * @param exec the executor to schedule
     * @param td the topology that the executor is a part of
     * @param rackId the rack id of the rack to find a worker on
     * @param scheduleAssignmentMap already calculated assignments
     * @return a worker to assign executor exec to. Returns null if a worker cannot be successfully found on rack with rackId
     */
private WorkerSlot getBestWorker(ExecutorDetails exec, TopologyDetails td, String rackId, Map<WorkerSlot, Collection<ExecutorDetails>> scheduleAssignmentMap) {
    if (!_rackIdToSortedNodes.containsKey(rackId)) {
        _rackIdToSortedNodes.put(rackId, sortNodes(this.getAvailableNodesFromRack(rackId), rackId, td.getId(), scheduleAssignmentMap));
    }
    TreeSet<ObjectResources> sortedNodes = _rackIdToSortedNodes.get(rackId);
    double taskMem = td.getTotalMemReqTask(exec);
    double taskCPU = td.getTotalCpuReqTask(exec);
    for (ObjectResources nodeResources : sortedNodes) {
        RAS_Node n = _nodes.getNodeById(nodeResources.id);
        if (n.getAvailableCpuResources() >= taskCPU && n.getAvailableMemoryResources() >= taskMem && n.getFreeSlots().size() > 0) {
            for (WorkerSlot ws : n.getFreeSlots()) {
                if (checkWorkerConstraints(exec, ws, td, scheduleAssignmentMap)) {
                    return ws;
                }
            }
        }
    }
    return null;
}
Also used : WorkerSlot(org.apache.storm.scheduler.WorkerSlot) RAS_Node(org.apache.storm.scheduler.resource.RAS_Node)

Example 4 with RAS_Node

use of org.apache.storm.scheduler.resource.RAS_Node in project storm by apache.

the class DefaultResourceAwareStrategy method sortNodes.

/**
     * Sorted Nodes
     *
     * @param availNodes            a list of all the nodes we want to sort
     * @param rackId                the rack id availNodes are a part of
     * @param topoId                the topology that we are trying to schedule
     * @param scheduleAssignmentMap calculated assignments so far
     * @return a sorted list of nodes
     * <p>
     * Nodes are sorted by two criteria. 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.
     * 2) the subordinate/subservient resource availability percentage of a node in descending order
     * We calculate the resource availability percentage by dividing the resource availability on the node by the resource availability of the entire rack
     * By doing this calculation, nodes that have exhausted or little of one of the resources mentioned above will be ranked after 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.
     */
private TreeSet<ObjectResources> sortNodes(List<RAS_Node> availNodes, String rackId, final String topoId, final Map<WorkerSlot, Collection<ExecutorDetails>> scheduleAssignmentMap) {
    AllResources allResources = new AllResources("RACK");
    List<ObjectResources> nodes = allResources.objectResources;
    final Map<String, String> nodeIdToRackId = new HashMap<String, String>();
    for (RAS_Node ras_node : availNodes) {
        String nodeId = ras_node.getId();
        ObjectResources node = new ObjectResources(nodeId);
        double availMem = ras_node.getAvailableMemoryResources();
        double availCpu = ras_node.getAvailableCpuResources();
        int freeSlots = ras_node.totalSlotsFree();
        double totalMem = ras_node.getTotalMemoryResources();
        double totalCpu = ras_node.getTotalCpuResources();
        int totalSlots = ras_node.totalSlots();
        node.availMem = availMem;
        node.totalMem = totalMem;
        node.availCpu = availCpu;
        node.totalCpu = totalCpu;
        nodes.add(node);
        allResources.availMemResourcesOverall += availMem;
        allResources.availCpuResourcesOverall += availCpu;
        allResources.totalMemResourcesOverall += totalMem;
        allResources.totalCpuResourcesOverall += totalCpu;
    }
    LOG.debug("Rack {}: Overall Avail [ CPU {} MEM {} ] Total [ CPU {} MEM {} ]", rackId, allResources.availCpuResourcesOverall, allResources.availMemResourcesOverall, allResources.totalCpuResourcesOverall, allResources.totalMemResourcesOverall);
    return sortObjectResources(allResources, new ExistingScheduleFunc() {

        @Override
        public int getNumExistingSchedule(String objectId) {
            //Get execs already assigned in rack
            Collection<ExecutorDetails> execs = new LinkedList<ExecutorDetails>();
            if (_cluster.getAssignmentById(topoId) != null) {
                for (Map.Entry<ExecutorDetails, WorkerSlot> entry : _cluster.getAssignmentById(topoId).getExecutorToSlot().entrySet()) {
                    WorkerSlot workerSlot = entry.getValue();
                    ExecutorDetails exec = entry.getKey();
                    if (workerSlot.getNodeId().equals(objectId)) {
                        execs.add(exec);
                    }
                }
            }
            // get execs already scheduled in the current scheduling
            for (Map.Entry<WorkerSlot, Collection<ExecutorDetails>> entry : scheduleAssignmentMap.entrySet()) {
                WorkerSlot workerSlot = entry.getKey();
                if (workerSlot.getNodeId().equals(objectId)) {
                    execs.addAll(entry.getValue());
                }
            }
            return execs.size();
        }
    });
}
Also used : ExecutorDetails(org.apache.storm.scheduler.ExecutorDetails) HashMap(java.util.HashMap) RAS_Node(org.apache.storm.scheduler.resource.RAS_Node) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) Collection(java.util.Collection)

Example 5 with RAS_Node

use of org.apache.storm.scheduler.resource.RAS_Node in project storm by apache.

the class DefaultResourceAwareStrategy method getClusterInfo.

/**
     * Get the amount of resources available and total for each node
     *
     * @return a String with cluster resource info for debug
     */
private String getClusterInfo() {
    String retVal = "Cluster info:\n";
    for (Map.Entry<String, List<String>> clusterEntry : _clusterInfo.entrySet()) {
        String clusterId = clusterEntry.getKey();
        retVal += "Rack: " + clusterId + "\n";
        for (String nodeHostname : clusterEntry.getValue()) {
            RAS_Node node = this.idToNode(this.NodeHostnameToId(nodeHostname));
            retVal += "-> Node: " + node.getHostname() + " " + node.getId() + "\n";
            retVal += "--> Avail Resources: {Mem " + node.getAvailableMemoryResources() + ", CPU " + node.getAvailableCpuResources() + " Slots: " + node.totalSlotsFree() + "}\n";
            retVal += "--> Total Resources: {Mem " + node.getTotalMemoryResources() + ", CPU " + node.getTotalCpuResources() + " Slots: " + node.totalSlots() + "}\n";
        }
    }
    return retVal;
}
Also used : ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) RAS_Node(org.apache.storm.scheduler.resource.RAS_Node) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

RAS_Node (org.apache.storm.scheduler.resource.RAS_Node)6 WorkerSlot (org.apache.storm.scheduler.WorkerSlot)5 HashMap (java.util.HashMap)4 ExecutorDetails (org.apache.storm.scheduler.ExecutorDetails)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Map (java.util.Map)3 Config (org.apache.storm.Config)1 DNSToSwitchMapping (org.apache.storm.networktopography.DNSToSwitchMapping)1 Cluster (org.apache.storm.scheduler.Cluster)1 INimbus (org.apache.storm.scheduler.INimbus)1 SchedulerAssignmentImpl (org.apache.storm.scheduler.SchedulerAssignmentImpl)1 SupervisorDetails (org.apache.storm.scheduler.SupervisorDetails)1 Topologies (org.apache.storm.scheduler.Topologies)1 TopologyDetails (org.apache.storm.scheduler.TopologyDetails)1 RAS_Nodes (org.apache.storm.scheduler.resource.RAS_Nodes)1 SchedulingResult (org.apache.storm.scheduler.resource.SchedulingResult)1 SchedulingState (org.apache.storm.scheduler.resource.SchedulingState)1