Search in sources :

Example 6 with Vertex

use of edu.iu.dsc.tws.api.compute.graph.Vertex in project twister2 by DSC-SPIDAL.

the class UserDefinedTaskScheduler method schedule.

/**
 * This is the base method which receives the dataflow taskgraph and the worker plan to allocate
 * the task instances to the appropriate workers with their required ram, disk, and cpu values.
 *
 * @return TaskSchedulePlan
 */
@Override
public TaskSchedulePlan schedule(ComputeGraph graph, WorkerPlan workerPlan) {
    int taskSchedulePlanId = 0;
    // Allocate the task instances into the containers/workers
    Set<WorkerSchedulePlan> workerSchedulePlans = new LinkedHashSet<>();
    // To get the vertex set from the taskgraph
    Set<Vertex> taskVertexSet = graph.getTaskVertexSet();
    // Allocate the task instances into the logical containers.
    Map<Integer, List<TaskInstanceId>> userDefinedContainerInstanceMap = userDefinedSchedulingAlgorithm(graph, workerPlan.getNumberOfWorkers());
    TaskInstanceMapCalculation instanceMapCalculation = new TaskInstanceMapCalculation(this.instanceRAM, this.instanceCPU, this.instanceDisk);
    Map<Integer, Map<TaskInstanceId, Double>> instancesRamMap = instanceMapCalculation.getInstancesRamMapInContainer(userDefinedContainerInstanceMap, taskVertexSet);
    Map<Integer, Map<TaskInstanceId, Double>> instancesDiskMap = instanceMapCalculation.getInstancesDiskMapInContainer(userDefinedContainerInstanceMap, taskVertexSet);
    Map<Integer, Map<TaskInstanceId, Double>> instancesCPUMap = instanceMapCalculation.getInstancesCPUMapInContainer(userDefinedContainerInstanceMap, taskVertexSet);
    for (int containerId : userDefinedContainerInstanceMap.keySet()) {
        double containerRAMValue = TaskSchedulerContext.containerRamPadding(config);
        double containerDiskValue = TaskSchedulerContext.containerDiskPadding(config);
        double containerCpuValue = TaskSchedulerContext.containerCpuPadding(config);
        List<TaskInstanceId> taskTaskInstanceIds = userDefinedContainerInstanceMap.get(containerId);
        Map<TaskInstanceId, TaskInstancePlan> taskInstancePlanMap = new HashMap<>();
        for (TaskInstanceId id : taskTaskInstanceIds) {
            double instanceRAMValue = instancesRamMap.get(containerId).get(id);
            double instanceDiskValue = instancesDiskMap.get(containerId).get(id);
            double instanceCPUValue = instancesCPUMap.get(containerId).get(id);
            Resource instanceResource = new Resource(instanceRAMValue, instanceDiskValue, instanceCPUValue);
            taskInstancePlanMap.put(id, new TaskInstancePlan(id.getTaskName(), id.getTaskId(), id.getTaskIndex(), instanceResource));
            containerRAMValue += instanceRAMValue;
            containerDiskValue += instanceDiskValue;
            containerCpuValue += instanceDiskValue;
        }
        Worker worker = workerPlan.getWorker(containerId);
        Resource containerResource;
        // Create the container resource value based on the worker plan
        if (worker != null && worker.getCpu() > 0 && worker.getDisk() > 0 && worker.getRam() > 0) {
            containerResource = new Resource((double) worker.getRam(), (double) worker.getDisk(), (double) worker.getCpu());
            LOG.fine("Worker (if loop):" + containerId + "\tRam:" + worker.getRam() + "\tDisk:" + worker.getDisk() + "\tCpu:" + worker.getCpu());
        } else {
            containerResource = new Resource(containerRAMValue, containerDiskValue, containerCpuValue);
            LOG.fine("Worker (else loop):" + containerId + "\tRam:" + containerRAMValue + "\tDisk:" + containerDiskValue + "\tCpu:" + containerCpuValue);
        }
        // Schedule the task instance plan into the task container plan.
        WorkerSchedulePlan taskWorkerSchedulePlan = new WorkerSchedulePlan(containerId, new HashSet<>(taskInstancePlanMap.values()), containerResource);
        workerSchedulePlans.add(taskWorkerSchedulePlan);
    }
    return new TaskSchedulePlan(taskSchedulePlanId, workerSchedulePlans);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Vertex(edu.iu.dsc.tws.api.compute.graph.Vertex) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Resource(edu.iu.dsc.tws.api.compute.schedule.elements.Resource) TaskInstanceId(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstanceId) TaskSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskSchedulePlan) WorkerSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan) TaskInstanceMapCalculation(edu.iu.dsc.tws.tsched.spi.taskschedule.TaskInstanceMapCalculation) TaskInstancePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan) Worker(edu.iu.dsc.tws.api.compute.schedule.elements.Worker) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 7 with Vertex

use of edu.iu.dsc.tws.api.compute.graph.Vertex in project twister2 by DSC-SPIDAL.

the class TaskAttributes method getTaskNetworkMap.

/**
 * This method retrieve the set of task vertices and check if the task vertex has the user
 * specified network value. If the user doesn't specify the required network configuration it will
 * assign the default network value from the task configuration file and store it in the map.
 */
public Map<String, Double> getTaskNetworkMap(Set<Vertex> taskVertices) {
    Map<String, Double> taskNetworkMap = new LinkedHashMap<>();
    Object network;
    double requiredNetwork;
    for (Vertex task : taskVertices) {
        Config config = task.getConfig();
        if (config.get("Network") != null) {
            network = config.get("Network");
            requiredNetwork = (double) ((Integer) network);
        } else {
            requiredNetwork = TaskSchedulerContext.taskInstanceNetwork(config);
        }
        taskNetworkMap.put(task.getName(), requiredNetwork);
    }
    return taskNetworkMap;
}
Also used : Vertex(edu.iu.dsc.tws.api.compute.graph.Vertex) Config(edu.iu.dsc.tws.api.config.Config) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with Vertex

use of edu.iu.dsc.tws.api.compute.graph.Vertex in project twister2 by DSC-SPIDAL.

the class TaskAttributes method getTaskCPUMap.

/**
 * This method retrieve the set of task vertices and check if the task vertex has the user
 * specified cpu value. If the user doesn't specify the required cpu configuration it will assign
 * the default cpu value from the task configuration file and store it in the map.
 */
public Map<String, Double> getTaskCPUMap(Set<Vertex> taskVertices) {
    Map<String, Double> taskCPUMap = new LinkedHashMap<>();
    Object cpu;
    double requiredCpu;
    for (Vertex task : taskVertices) {
        Config config = task.getConfig();
        if (config.get("Cpu") != null) {
            cpu = config.get("Cpu");
            requiredCpu = (double) ((Integer) cpu);
        } else {
            requiredCpu = TaskSchedulerContext.taskInstanceCpu(config);
        }
        taskCPUMap.put(task.getName(), requiredCpu);
    }
    return taskCPUMap;
}
Also used : Vertex(edu.iu.dsc.tws.api.compute.graph.Vertex) Config(edu.iu.dsc.tws.api.config.Config) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with Vertex

use of edu.iu.dsc.tws.api.compute.graph.Vertex in project twister2 by DSC-SPIDAL.

the class TaskAttributes method getParallelTaskMap.

/**
 * This method is mainly to generate the parallel task map (maintain order) for the task vertex.
 * If the user specifies the parallelism value greater than or equal "1" will be considered as a
 * parallelism value. Otherwise, the system assign the default parallelism value to the task
 * vertex from the task scheduling configuration file.
 */
public Map<String, Integer> getParallelTaskMap(Set<Vertex> iTaskSet, Map<String, Map<String, String>> nodeConstraintsMap) {
    Map<String, Integer> parallelTaskMap = new LinkedHashMap<>();
    for (Vertex taskVertex : iTaskSet) {
        Config config = taskVertex.getConfig();
        String taskName = taskVertex.getName();
        int parallelTaskCount;
        if (!nodeConstraintsMap.get(taskName).isEmpty()) {
            Map<String, String> vertexMap = nodeConstraintsMap.get(taskName);
            if (vertexMap.containsKey(Context.TWISTER2_TASK_INSTANCE_ODD_PARALLELISM)) {
                parallelTaskCount = Integer.valueOf(String.valueOf(vertexMap.get(Context.TWISTER2_TASK_INSTANCE_ODD_PARALLELISM)));
            } else {
                parallelTaskCount = taskVertex.getParallelism();
            }
        } else {
            if (taskVertex.getParallelism() >= 1) {
                parallelTaskCount = taskVertex.getParallelism();
            } else {
                parallelTaskCount = TaskSchedulerContext.taskParallelism(config);
            }
        }
        parallelTaskMap.put(taskName, parallelTaskCount);
    }
    return parallelTaskMap;
}
Also used : Vertex(edu.iu.dsc.tws.api.compute.graph.Vertex) Config(edu.iu.dsc.tws.api.config.Config) LinkedHashMap(java.util.LinkedHashMap)

Example 10 with Vertex

use of edu.iu.dsc.tws.api.compute.graph.Vertex in project twister2 by DSC-SPIDAL.

the class GraphBuilder method setParallelism.

public GraphBuilder setParallelism(String taskName, int parallel) {
    Vertex v = graph.vertex(taskName);
    if (v == null) {
        throw new RuntimeException("Failed to add configuration to non-existing task: " + taskName);
    }
    v.setParallelism(parallel);
    return this;
}
Also used : Vertex(edu.iu.dsc.tws.api.compute.graph.Vertex)

Aggregations

Vertex (edu.iu.dsc.tws.api.compute.graph.Vertex)27 LinkedHashMap (java.util.LinkedHashMap)15 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)11 List (java.util.List)11 TaskInstanceId (edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstanceId)10 Map (java.util.Map)10 Resource (edu.iu.dsc.tws.api.compute.schedule.elements.Resource)8 TaskInstancePlan (edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan)8 TaskSchedulePlan (edu.iu.dsc.tws.api.compute.schedule.elements.TaskSchedulePlan)8 WorkerSchedulePlan (edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan)8 Config (edu.iu.dsc.tws.api.config.Config)8 LinkedHashSet (java.util.LinkedHashSet)8 Worker (edu.iu.dsc.tws.api.compute.schedule.elements.Worker)7 TaskInstanceMapCalculation (edu.iu.dsc.tws.tsched.spi.taskschedule.TaskInstanceMapCalculation)7 TreeSet (java.util.TreeSet)6 TaskSchedulerException (edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException)4 TaskAttributes (edu.iu.dsc.tws.tsched.utils.TaskAttributes)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4