Exemplo n.º 1
0
 private List<WorkerSlot> getAvailableWorkersFromCluster(String clusterId) {
   List<RAS_Node> nodes = this.getAvailableNodesFromCluster(clusterId);
   List<WorkerSlot> workers = new LinkedList<WorkerSlot>();
   for (RAS_Node node : nodes) {
     workers.addAll(node.getFreeSlots());
   }
   return workers;
 }
Exemplo n.º 2
0
 private String NodeToCluster(RAS_Node node) {
   for (Entry<String, List<String>> entry : _clusterInfo.entrySet()) {
     if (entry.getValue().contains(node.getHostname())) {
       return entry.getKey();
     }
   }
   LOG.error("Node: {} not found in any clusters", node.getHostname());
   return null;
 }
Exemplo n.º 3
0
 private Double distToNode(RAS_Node src, RAS_Node dest) {
   if (src.getId().equals(dest.getId()) == true) {
     return 1.0;
   } else if (this.NodeToCluster(src) == this.NodeToCluster(dest)) {
     return 2.0;
   } else {
     return 3.0;
   }
 }
Exemplo n.º 4
0
 /**
  * hostname to Id
  *
  * @param hostname
  * @return the id of a node
  */
 public String NodeHostnameToId(String hostname) {
   for (RAS_Node n : _nodes.values()) {
     if (n.getHostname() == null) {
       continue;
     }
     if (n.getHostname().equals(hostname)) {
       return n.getId();
     }
   }
   LOG.error("Cannot find Node with hostname {}", hostname);
   return null;
 }
Exemplo n.º 5
0
  private WorkerSlot getBestWorker(
      ExecutorDetails exec,
      TopologyDetails td,
      String clusterId,
      Map<WorkerSlot, Collection<ExecutorDetails>> scheduleAssignmentMap) {
    double taskMem = td.getTotalMemReqTask(exec);
    double taskCPU = td.getTotalCpuReqTask(exec);
    List<RAS_Node> nodes;
    if (clusterId != null) {
      nodes = this.getAvailableNodesFromCluster(clusterId);

    } else {
      nodes = this.getAvailableNodes();
    }
    // First sort nodes by distance
    TreeMap<Double, RAS_Node> nodeRankMap = new TreeMap<Double, RAS_Node>();
    for (RAS_Node n : nodes) {
      if (n.getFreeSlots().size() > 0) {
        if (n.getAvailableMemoryResources() >= taskMem && n.getAvailableCpuResources() >= taskCPU) {
          double a =
              Math.pow(
                  ((taskCPU - n.getAvailableCpuResources()) / (n.getAvailableCpuResources() + 1))
                      * this.CPU_WEIGHT,
                  2);
          double b =
              Math.pow(
                  ((taskMem - n.getAvailableMemoryResources())
                          / (n.getAvailableMemoryResources() + 1))
                      * this.MEM_WEIGHT,
                  2);
          double c = 0.0;
          if (this.refNode != null) {
            c = Math.pow(this.distToNode(this.refNode, n) * this.NETWORK_WEIGHT, 2);
          }
          double distance = Math.sqrt(a + b + c);
          nodeRankMap.put(distance, n);
        }
      }
    }
    // Then, pick worker from closest node that satisfy constraints
    for (Map.Entry<Double, RAS_Node> entry : nodeRankMap.entrySet()) {
      RAS_Node n = entry.getValue();
      for (WorkerSlot ws : n.getFreeSlots()) {
        if (checkWorkerConstraints(exec, ws, td, scheduleAssignmentMap)) {
          return ws;
        }
      }
    }
    return null;
  }
Exemplo n.º 6
0
 public ResourceAwareStrategy(Cluster cluster, Topologies topologies) {
   _topologies = topologies;
   _cluster = cluster;
   _nodes = RAS_Node.getAllNodesFrom(cluster, _topologies);
   _availNodes = this.getAvailNodes();
   this.LOG = LoggerFactory.getLogger(this.getClass());
   _clusterInfo = cluster.getNetworkTopography();
   LOG.debug(this.getClusterInfo());
 }
Exemplo n.º 7
0
 /**
  * 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 (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()
               + "}\n";
       retVal +=
           "--> Total Resources: {Mem "
               + node.getTotalMemoryResources()
               + ", CPU "
               + node.getTotalCpuResources()
               + "}\n";
     }
   }
   return retVal;
 }
Exemplo n.º 8
0
  public Map<WorkerSlot, Collection<ExecutorDetails>> schedule(TopologyDetails td) {
    if (_availNodes.size() <= 0) {
      LOG.warn("No available nodes to schedule tasks on!");
      return null;
    }
    Collection<ExecutorDetails> unassignedExecutors = _cluster.getUnassignedExecutors(td);
    Map<WorkerSlot, Collection<ExecutorDetails>> schedulerAssignmentMap =
        new HashMap<WorkerSlot, Collection<ExecutorDetails>>();
    LOG.debug("ExecutorsNeedScheduling: {}", unassignedExecutors);
    Collection<ExecutorDetails> scheduledTasks = new ArrayList<ExecutorDetails>();
    List<Component> spouts = this.getSpouts(_topologies, td);

    if (spouts.size() == 0) {
      LOG.error("Cannot find a Spout!");
      return null;
    }

    Queue<Component> ordered__Component_list = bfs(_topologies, td, spouts);

    Map<Integer, List<ExecutorDetails>> priorityToExecutorMap =
        getPriorityToExecutorDetailsListMap(ordered__Component_list, unassignedExecutors);
    Collection<ExecutorDetails> executorsNotScheduled =
        new HashSet<ExecutorDetails>(unassignedExecutors);
    Integer longestPriorityListSize = this.getLongestPriorityListSize(priorityToExecutorMap);
    // Pick the first executor with priority one, then the 1st exec with priority 2, so on an so
    // forth.
    // Once we reach the last priority, we go back to priority 1 and schedule the second task with
    // priority 1.
    for (int i = 0; i < longestPriorityListSize; i++) {
      for (Entry<Integer, List<ExecutorDetails>> entry : priorityToExecutorMap.entrySet()) {
        Iterator<ExecutorDetails> it = entry.getValue().iterator();
        if (it.hasNext()) {
          ExecutorDetails exec = it.next();
          LOG.debug(
              "\n\nAttempting to schedule: {} of component {}[avail {}] with rank {}",
              new Object[] {
                exec,
                td.getExecutorToComponent().get(exec),
                td.getTaskResourceReqList(exec),
                entry.getKey()
              });
          WorkerSlot targetSlot = this.findWorkerForExec(exec, td, schedulerAssignmentMap);
          if (targetSlot != null) {
            RAS_Node targetNode = this.idToNode(targetSlot.getNodeId());
            if (!schedulerAssignmentMap.containsKey(targetSlot)) {
              schedulerAssignmentMap.put(targetSlot, new LinkedList<ExecutorDetails>());
            }

            schedulerAssignmentMap.get(targetSlot).add(exec);
            targetNode.consumeResourcesforTask(exec, td);
            scheduledTasks.add(exec);
            LOG.debug(
                "TASK {} assigned to Node: {} avail [mem: {} cpu: {}] total [mem: {} cpu: {}] on slot: {}",
                exec,
                targetNode,
                targetNode.getAvailableMemoryResources(),
                targetNode.getAvailableCpuResources(),
                targetNode.getTotalMemoryResources(),
                targetNode.getTotalCpuResources(),
                targetSlot);
          } else {
            LOG.error("Not Enough Resources to schedule Task {}", exec);
          }
          it.remove();
        }
      }
    }

    executorsNotScheduled.removeAll(scheduledTasks);
    LOG.debug("/* Scheduling left over task (most likely sys tasks) */");
    // schedule left over system tasks
    for (ExecutorDetails exec : executorsNotScheduled) {
      WorkerSlot targetSlot = this.findWorkerForExec(exec, td, schedulerAssignmentMap);
      if (targetSlot != null) {
        RAS_Node targetNode = this.idToNode(targetSlot.getNodeId());
        if (schedulerAssignmentMap.containsKey(targetSlot) == false) {
          schedulerAssignmentMap.put(targetSlot, new LinkedList<ExecutorDetails>());
        }

        schedulerAssignmentMap.get(targetSlot).add(exec);
        targetNode.consumeResourcesforTask(exec, td);
        scheduledTasks.add(exec);
        LOG.debug(
            "TASK {} assigned to Node: {} avail [mem: {} cpu: {}] total [mem: {} cpu: {}] on slot: {}",
            exec,
            targetNode,
            targetNode.getAvailableMemoryResources(),
            targetNode.getAvailableCpuResources(),
            targetNode.getTotalMemoryResources(),
            targetNode.getTotalCpuResources(),
            targetSlot);
      } else {
        LOG.error("Not Enough Resources to schedule Task {}", exec);
      }
    }
    executorsNotScheduled.removeAll(scheduledTasks);
    if (executorsNotScheduled.size() > 0) {
      LOG.error("Not all executors successfully scheduled: {}", executorsNotScheduled);
      schedulerAssignmentMap = null;
    } else {
      LOG.debug("All resources successfully scheduled!");
    }
    if (schedulerAssignmentMap == null) {
      LOG.error("Topology {} not successfully scheduled!", td.getId());
    }
    return schedulerAssignmentMap;
  }