Search in sources :

Example 31 with WorkerSchedulePlan

use of edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan in project twister2 by DSC-SPIDAL.

the class RoundRobinTaskScheduler 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 computeGraph, WorkerPlan workerPlan) {
    // Allocate the task instances into the containers/workers
    Set<WorkerSchedulePlan> workerSchedulePlans = new LinkedHashSet<>();
    // To get the vertex set from the taskgraph
    Set<Vertex> taskVertexSet = new LinkedHashSet<>(computeGraph.getTaskVertexSet());
    // Allocate the task instances into the logical containers.
    Map<Integer, List<TaskInstanceId>> roundRobinContainerInstanceMap = roundRobinSchedulingAlgorithm(computeGraph, workerPlan.getNumberOfWorkers());
    TaskInstanceMapCalculation instanceMapCalculation = new TaskInstanceMapCalculation(this.instanceRAM, this.instanceCPU, this.instanceDisk);
    Map<Integer, Map<TaskInstanceId, Double>> instancesRamMap = instanceMapCalculation.getInstancesRamMapInContainer(roundRobinContainerInstanceMap, taskVertexSet);
    Map<Integer, Map<TaskInstanceId, Double>> instancesDiskMap = instanceMapCalculation.getInstancesDiskMapInContainer(roundRobinContainerInstanceMap, taskVertexSet);
    Map<Integer, Map<TaskInstanceId, Double>> instancesCPUMap = instanceMapCalculation.getInstancesCPUMapInContainer(roundRobinContainerInstanceMap, taskVertexSet);
    for (int containerId : roundRobinContainerInstanceMap.keySet()) {
        double containerRAMValue = TaskSchedulerContext.containerRamPadding(config);
        double containerDiskValue = TaskSchedulerContext.containerDiskPadding(config);
        double containerCpuValue = TaskSchedulerContext.containerCpuPadding(config);
        List<TaskInstanceId> taskTaskInstanceIds = roundRobinContainerInstanceMap.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());
        } else {
            containerResource = new Resource(containerRAMValue, containerDiskValue, containerCpuValue);
        }
        // Schedule the task instance plan into the task container plan.
        WorkerSchedulePlan taskWorkerSchedulePlan = new WorkerSchedulePlan(containerId, new LinkedHashSet<>(taskInstancePlanMap.values()), containerResource);
        workerSchedulePlans.add(taskWorkerSchedulePlan);
    }
    return new TaskSchedulePlan(0, 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)

Aggregations

WorkerSchedulePlan (edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan)31 TaskInstancePlan (edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan)29 TaskSchedulePlan (edu.iu.dsc.tws.api.compute.schedule.elements.TaskSchedulePlan)27 Map (java.util.Map)26 ComputeGraph (edu.iu.dsc.tws.api.compute.graph.ComputeGraph)21 WorkerPlan (edu.iu.dsc.tws.api.compute.schedule.elements.WorkerPlan)20 TaskSchedulerClassTest (edu.iu.dsc.tws.tsched.utils.TaskSchedulerClassTest)19 Test (org.junit.Test)19 HashMap (java.util.HashMap)10 Resource (edu.iu.dsc.tws.api.compute.schedule.elements.Resource)9 Config (edu.iu.dsc.tws.api.config.Config)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Vertex (edu.iu.dsc.tws.api.compute.graph.Vertex)7 TaskInstanceId (edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstanceId)7 Worker (edu.iu.dsc.tws.api.compute.schedule.elements.Worker)6 TaskInstanceMapCalculation (edu.iu.dsc.tws.tsched.spi.taskschedule.TaskInstanceMapCalculation)6 HashSet (java.util.HashSet)6 LinkedHashSet (java.util.LinkedHashSet)6 LinkedHashMap (java.util.LinkedHashMap)5