Search in sources :

Example 6 with TaskInstancePlan

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

the class TaskSchedulePlanBuilder method addInstance.

public TaskSchedulePlanBuilder addInstance(Integer containerId, String taskName) throws TaskSchedulerException {
    initContainer(containerId);
    int taskId = taskIds.isEmpty() ? 1 : taskIds.last() + 1;
    int taskIndex = taskIndexes.get(taskName) != null ? taskIndexes.get(taskName).last() + 1 : 0;
    TaskInstanceId taskInstanceId = new TaskInstanceId(taskName, taskId, taskIndex);
    Resource resource = TaskScheduleUtils.getResourceRequirement(taskName, this.taskRamMap, this.instanceDefaultResourceValue, this.containerMaximumResourceValue, this.requestedContainerPadding);
    try {
        addToContainer(containers.get(containerId), new TaskInstancePlan(taskInstanceId, resource), taskIndexes, taskIds);
    } catch (TaskSchedulerException e) {
        throw new TaskSchedulerException(String.format("Insufficient container resources to add instance %s with resources %s to container %d.", taskInstanceId, resource, containerId), e);
    }
    LOG.info("Task id, index, name:" + taskId + "\t" + taskIndex + "\t" + taskName + "\tadded to Container:" + containers.get(containerId));
    return this;
}
Also used : TaskInstanceId(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstanceId) TaskInstancePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan) Resource(edu.iu.dsc.tws.api.compute.schedule.elements.Resource) TaskSchedulerException(edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException)

Example 7 with TaskInstancePlan

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

the class TaskSchedulePlanBuilder method getContainers.

/**
 * Get the containers based on the task schedule plan
 */
private Map<Integer, Container> getContainers(TaskSchedulePlan previoustaskschedulePlan) throws TaskSchedulerException {
    Map<Integer, Container> containerMap = new HashMap<>();
    Resource resource = previoustaskschedulePlan.getMaxContainerResources();
    for (WorkerSchedulePlan currentWorkerSchedulePlan : previoustaskschedulePlan.getContainers()) {
        Container container = new Container(currentWorkerSchedulePlan.getContainerId(), resource, requestedContainerPadding);
        for (TaskInstancePlan instancePlan : currentWorkerSchedulePlan.getTaskInstances()) {
            try {
                addToContainer(container, instancePlan, taskIndexes, taskIds);
            } catch (TaskSchedulerException e) {
                throw new TaskSchedulerException(String.format("Insufficient container resources to add instancePlan %s to container %s", instancePlan, container), e);
            }
        }
        containerMap.put(currentWorkerSchedulePlan.getContainerId(), container);
    }
    return containerMap;
}
Also used : WorkerSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan) HashMap(java.util.HashMap) TaskInstancePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan) Resource(edu.iu.dsc.tws.api.compute.schedule.elements.Resource) TaskSchedulerException(edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException)

Example 8 with TaskInstancePlan

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

the class TaskSchedulePlanBuilder method getContainers.

/**
 * Get the containers based on the task schedule plan
 * @param previoustaskschedulePlan
 * @return
 * @throws TaskSchedulerException
 */
private Map<Integer, Container> getContainers(TaskSchedulePlan previoustaskschedulePlan, int containerPadding, Map<String, TreeSet<Integer>> taskindexes, TreeSet<Integer> taskids) throws TaskSchedulerException {
    Map<Integer, Container> containerMap = new HashMap<>();
    Resource resource = previoustaskschedulePlan.getMaxContainerResources();
    for (WorkerSchedulePlan currentWorkerSchedulePlan : previoustaskschedulePlan.getContainers()) {
        Container container = new Container(currentWorkerSchedulePlan.getContainerId(), resource, containerPadding);
        for (TaskInstancePlan instancePlan : currentWorkerSchedulePlan.getTaskInstances()) {
            try {
                addToContainer(container, instancePlan, taskindexes, taskids);
            } catch (TaskSchedulerException e) {
                throw new TaskSchedulerException(String.format("Insufficient container resources to add instancePlan %s to container %s", instancePlan, container), e);
            }
        }
        containerMap.put(currentWorkerSchedulePlan.getContainerId(), container);
    }
    return containerMap;
}
Also used : WorkerSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan) HashMap(java.util.HashMap) TaskInstancePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan) Resource(edu.iu.dsc.tws.api.compute.schedule.elements.Resource) TaskSchedulerException(edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException)

Example 9 with TaskInstancePlan

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

the class TaskSchedulePlanBuilder method buildContainerPlans.

private Set<WorkerSchedulePlan> buildContainerPlans(Map<Integer, Container> containerValue, Map<String, Double> taskramMap, Resource instdefaultresourcevalue) {
    Set<WorkerSchedulePlan> workerSchedulePlans = new LinkedHashSet<>();
    try {
        for (Integer containerId : containerValue.keySet()) {
            Container container = containerValue.get(containerId);
            if (container.getTaskInstances().size() == 0) {
                continue;
            }
            double containerRAMValue = 0.0;
            double containerDiskValue = 0.0;
            double containerCPUValue = 0.0;
            Set<TaskInstancePlan> taskInstancePlans = new HashSet<>();
            for (TaskInstancePlan taskInstancePlan : container.getTaskInstances()) {
                TaskInstanceId taskInstanceId = new TaskInstanceId(taskInstancePlan.getTaskName(), taskInstancePlan.getTaskId(), taskInstancePlan.getTaskIndex());
                double instanceRAMValue;
                if (taskramMap.containsKey(taskInstanceId.getTaskName())) {
                    instanceRAMValue = taskramMap.get(taskInstanceId.getTaskName());
                } else {
                    instanceRAMValue = instdefaultresourcevalue.getRam();
                }
                containerRAMValue += instanceRAMValue;
                double instanceDiskValue = instdefaultresourcevalue.getDisk();
                containerDiskValue += instanceDiskValue;
                double instanceCPUValue = instdefaultresourcevalue.getCpu();
                containerCPUValue += instanceCPUValue;
                LOG.fine("Resource Container Values:" + "Ram Value:" + containerRAMValue + "\t" + "Cpu Value:" + containerCPUValue + "\t" + "Disk Value:" + containerDiskValue);
                Resource resource = new Resource(instanceRAMValue, instanceDiskValue, instanceCPUValue);
                taskInstancePlans.add(new TaskInstancePlan(taskInstanceId.getTaskName(), taskInstanceId.getTaskId(), taskInstanceId.getTaskIndex(), resource));
            }
            containerCPUValue += (requestedContainerPadding * containerCPUValue) / 100;
            containerRAMValue += containerRAMValue + requestedContainerPadding;
            containerDiskValue += containerDiskValue + requestedContainerPadding;
            Resource resource = new Resource(containerRAMValue, containerDiskValue, containerCPUValue);
            WorkerSchedulePlan workerSchedulePlan = new WorkerSchedulePlan(containerId, taskInstancePlans, resource);
            workerSchedulePlans.add(workerSchedulePlan);
        }
    } catch (TaskSchedulerException ne) {
        throw new RuntimeException("Exception Occured" + ne.getMessage());
    }
    return workerSchedulePlans;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Resource(edu.iu.dsc.tws.api.compute.schedule.elements.Resource) TaskSchedulerException(edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException) TaskInstanceId(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstanceId) WorkerSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan) TaskInstancePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 10 with TaskInstancePlan

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

the class RoundRobinTaskSchedulerTest method testUniqueSchedules3.

@Test
public void testUniqueSchedules3() {
    int parallel = 16;
    int workers = 2;
    ComputeGraph graph = createGraphWithGraphConstraints(parallel);
    RoundRobinTaskScheduler scheduler = new RoundRobinTaskScheduler();
    scheduler.initialize(Config.newBuilder().build());
    WorkerPlan workerPlan = createWorkPlan(workers);
    TaskSchedulePlan plan1 = scheduler.schedule(graph, workerPlan);
    Map<Integer, WorkerSchedulePlan> containersMap = plan1.getContainersMap();
    for (Map.Entry<Integer, WorkerSchedulePlan> entry : containersMap.entrySet()) {
        WorkerSchedulePlan workerSchedulePlan = entry.getValue();
        Set<TaskInstancePlan> containerPlanTaskInstances = workerSchedulePlan.getTaskInstances();
        Assert.assertEquals(containerPlanTaskInstances.size(), Integer.parseInt(graph.getGraphConstraints().get(Context.TWISTER2_MAX_TASK_INSTANCES_PER_WORKER)));
    }
}
Also used : TaskSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskSchedulePlan) WorkerSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan) TaskInstancePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan) ComputeGraph(edu.iu.dsc.tws.api.compute.graph.ComputeGraph) Map(java.util.Map) WorkerPlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerPlan) Test(org.junit.Test) TaskSchedulerClassTest(edu.iu.dsc.tws.tsched.utils.TaskSchedulerClassTest)

Aggregations

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