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;
}
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;
}
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;
}
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;
}
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)));
}
}
Aggregations