use of edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan 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;
}
use of edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan 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;
}
use of edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan 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)));
}
}
use of edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan in project twister2 by DSC-SPIDAL.
the class RoundRobinTaskSchedulerTest method testUniqueSchedules2.
@Test
public void testUniqueSchedules2() {
int parallel = 256;
ComputeGraph graph = createGraph(parallel);
RoundRobinTaskScheduler scheduler = new RoundRobinTaskScheduler();
scheduler.initialize(Config.newBuilder().build());
WorkerPlan workerPlan = createWorkPlan(parallel);
TaskSchedulePlan plan1 = scheduler.schedule(graph, workerPlan);
WorkerPlan workerPlan2 = createWorkPlan2(parallel);
for (int i = 0; i < 1000; i++) {
TaskSchedulePlan plan2 = scheduler.schedule(graph, workerPlan2);
Assert.assertEquals(plan1.getContainers().size(), plan2.getContainers().size());
Map<Integer, WorkerSchedulePlan> map2 = plan2.getContainersMap();
for (WorkerSchedulePlan workerSchedulePlan : plan1.getContainers()) {
WorkerSchedulePlan p2 = map2.get(workerSchedulePlan.getContainerId());
Assert.assertTrue(containerEquals(workerSchedulePlan, p2));
}
}
}
use of edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan in project twister2 by DSC-SPIDAL.
the class RoundRobinTaskSchedulerTest method testUniqueSchedules.
@Test
public void testUniqueSchedules() {
int parallel = 256;
ComputeGraph graph = createGraph(parallel);
RoundRobinTaskScheduler scheduler = new RoundRobinTaskScheduler();
scheduler.initialize(Config.newBuilder().build());
WorkerPlan workerPlan = createWorkPlan(parallel);
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> map2 = plan2.getContainersMap();
for (WorkerSchedulePlan workerSchedulePlan : plan1.getContainers()) {
WorkerSchedulePlan p2 = map2.get(workerSchedulePlan.getContainerId());
Assert.assertTrue(containerEquals(workerSchedulePlan, p2));
}
}
}
Aggregations