Search in sources :

Example 21 with TaskSchedulePlan

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

the class TaskScheduler method generateTaskSchedulePlan.

private TaskSchedulePlan generateTaskSchedulePlan(String className) {
    Class<?> taskSchedulerClass;
    Method method;
    TaskSchedulePlan taskSchedulePlan;
    try {
        taskSchedulerClass = getClass().getClassLoader().loadClass(className);
        Object newInstance = taskSchedulerClass.newInstance();
        method = taskSchedulerClass.getMethod("initialize", new Class<?>[] { Config.class });
        method.invoke(newInstance, config);
        method = taskSchedulerClass.getMethod("schedule", new Class<?>[] { ComputeGraph.class, WorkerPlan.class });
        taskSchedulePlan = (TaskSchedulePlan) method.invoke(newInstance, computeGraph, workerPlan);
    } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException | InstantiationException | ClassNotFoundException | TaskSchedulerException e) {
        throw new Twister2RuntimeException(e);
    }
    if (taskSchedulePlan != null) {
        Map<Integer, WorkerSchedulePlan> containersMap = taskSchedulePlan.getContainersMap();
        for (Map.Entry<Integer, WorkerSchedulePlan> entry : containersMap.entrySet()) {
            Integer integer = entry.getKey();
            WorkerSchedulePlan workerSchedulePlan = entry.getValue();
            Set<TaskInstancePlan> containerPlanTaskInstances = workerSchedulePlan.getTaskInstances();
            LOG.fine("Task Details for Container Id:" + integer);
            for (TaskInstancePlan ip : containerPlanTaskInstances) {
                LOG.fine("Task Id:" + ip.getTaskId() + "\tTask Index" + ip.getTaskIndex() + "\tTask Name:" + ip.getTaskName());
            }
        }
    }
    return taskSchedulePlan;
}
Also used : Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) Config(edu.iu.dsc.tws.api.config.Config) ComputeGraph(edu.iu.dsc.tws.api.compute.graph.ComputeGraph) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) TaskSchedulerException(edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException) WorkerPlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerPlan) 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) Map(java.util.Map)

Example 22 with TaskSchedulePlan

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

the class BatchTaskSchedulerTest method testUniqueSchedules1.

@Test
public void testUniqueSchedules1() {
    int parallel = 16;
    int workers = 2;
    ComputeGraph graph = createGraph(parallel, "graph");
    BatchTaskScheduler scheduler = new BatchTaskScheduler();
    scheduler.initialize(Config.newBuilder().build());
    WorkerPlan workerPlan = createWorkPlan(workers);
    for (int i = 0; i < 1; i++) {
        TaskSchedulePlan plan1 = scheduler.schedule(graph, workerPlan);
        TaskSchedulePlan plan2 = scheduler.schedule(graph, workerPlan);
        Assert.assertEquals(plan1.getContainers().size(), plan2.getContainers().size());
        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(), graph.vertex("source").getParallelism());
        }
    }
}
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)

Example 23 with TaskSchedulePlan

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

the class BatchTaskSchedulerTest method testUniqueSchedules2.

@Test
public void testUniqueSchedules2() {
    int parallel = 16;
    int workers = 2;
    ComputeGraph graph = createGraph(parallel, "graph");
    BatchTaskScheduler scheduler = new BatchTaskScheduler();
    scheduler.initialize(Config.newBuilder().build());
    WorkerPlan workerPlan = createWorkPlan(workers);
    TaskSchedulePlan plan1 = scheduler.schedule(graph, workerPlan);
    WorkerPlan workerPlan2 = createWorkPlan2(workers);
    for (int i = 0; i < 1000; i++) {
        TaskSchedulePlan plan2 = scheduler.schedule(graph, workerPlan2);
        Assert.assertEquals(plan1.getContainers().size(), plan2.getContainers().size());
    }
}
Also used : TaskSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskSchedulePlan) ComputeGraph(edu.iu.dsc.tws.api.compute.graph.ComputeGraph) WorkerPlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerPlan) Test(org.junit.Test) TaskSchedulerClassTest(edu.iu.dsc.tws.tsched.utils.TaskSchedulerClassTest)

Example 24 with TaskSchedulePlan

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

the class BatchTaskSchedulerTest method testUniqueSchedules3.

@Test
public void testUniqueSchedules3() {
    int parallel = 16;
    int workers = 2;
    ComputeGraph graph = createGraphWithComputeTaskAndConstraints(parallel, "graph");
    BatchTaskScheduler scheduler = new BatchTaskScheduler();
    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() / graph.getTaskVertexSet().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)

Example 25 with TaskSchedulePlan

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

the class BatchTaskSchedulerTest method testUniqueSchedules7.

@Test
public void testUniqueSchedules7() {
    int parallel = 2;
    int workers = 4;
    ComputeGraph[] graph = new ComputeGraph[3];
    graph[0] = createGraphWithDifferentParallelismInput(parallel, "graph" + 0, "a");
    graph[1] = createGraphWithDifferentParallelismInput(parallel, "graph" + 1, "b");
    // if you specify any parallel value other than 2, it will throw
    // edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException: Please verify the dependent
    // collector(s) and receptor(s) parallelism values which are not equal
    graph[2] = createGraphWithDifferentParallelismInput(parallel, "graph" + 2, "b");
    BatchTaskScheduler scheduler = new BatchTaskScheduler();
    scheduler.initialize(Config.newBuilder().build());
    WorkerPlan workerPlan = createWorkPlan(workers);
    Map<String, TaskSchedulePlan> plan1 = scheduler.schedule(workerPlan, graph);
    for (Map.Entry<String, TaskSchedulePlan> taskSchedulePlanEntry : plan1.entrySet()) {
        TaskSchedulePlan plan2 = taskSchedulePlanEntry.getValue();
        Map<Integer, WorkerSchedulePlan> containersMap = plan2.getContainersMap();
        int index = 0;
        for (Map.Entry<Integer, WorkerSchedulePlan> entry : containersMap.entrySet()) {
            WorkerSchedulePlan workerSchedulePlan = entry.getValue();
            Set<TaskInstancePlan> containerPlanTaskInstances = workerSchedulePlan.getTaskInstances();
            index++;
            if (index <= parallel) {
                Assert.assertEquals(containerPlanTaskInstances.size(), workers / parallel);
            } else {
                Assert.assertEquals(containerPlanTaskInstances.size(), 0);
            }
        }
    }
}
Also used : ComputeGraph(edu.iu.dsc.tws.api.compute.graph.ComputeGraph) WorkerPlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerPlan) 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) Map(java.util.Map) Test(org.junit.Test) TaskSchedulerClassTest(edu.iu.dsc.tws.tsched.utils.TaskSchedulerClassTest)

Aggregations

TaskSchedulePlan (edu.iu.dsc.tws.api.compute.schedule.elements.TaskSchedulePlan)36 WorkerPlan (edu.iu.dsc.tws.api.compute.schedule.elements.WorkerPlan)28 WorkerSchedulePlan (edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan)27 ComputeGraph (edu.iu.dsc.tws.api.compute.graph.ComputeGraph)25 TaskInstancePlan (edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan)25 Map (java.util.Map)25 TaskSchedulerClassTest (edu.iu.dsc.tws.tsched.utils.TaskSchedulerClassTest)23 Test (org.junit.Test)23 Config (edu.iu.dsc.tws.api.config.Config)12 Vertex (edu.iu.dsc.tws.api.compute.graph.Vertex)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 List (java.util.List)7 Resource (edu.iu.dsc.tws.api.compute.schedule.elements.Resource)6 TaskInstanceId (edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstanceId)6 Worker (edu.iu.dsc.tws.api.compute.schedule.elements.Worker)6 TaskInstanceMapCalculation (edu.iu.dsc.tws.tsched.spi.taskschedule.TaskInstanceMapCalculation)6 LinkedHashMap (java.util.LinkedHashMap)5 LinkedHashSet (java.util.LinkedHashSet)5 HashSet (java.util.HashSet)4