use of edu.iu.dsc.tws.api.compute.graph.Vertex in project twister2 by DSC-SPIDAL.
the class RoundRobinTaskScheduler method roundRobinSchedulingAlgorithm.
/**
* This method retrieves the parallel task map and the total number of task instances for the task
* vertex set. Then, it will allocate the instances into the number of containers allocated for
* the task in a round robin fashion.
*/
private Map<Integer, List<TaskInstanceId>> roundRobinSchedulingAlgorithm(ComputeGraph graph, int numberOfContainers) throws TaskSchedulerException {
Map<Integer, List<TaskInstanceId>> roundrobinAllocation = new LinkedHashMap<>();
for (int i = 0; i < numberOfContainers; i++) {
roundrobinAllocation.put(i, new ArrayList<>());
}
Set<Vertex> taskVertexSet = new LinkedHashSet<>(graph.getTaskVertexSet());
TreeSet<Vertex> orderedTaskSet = new TreeSet<>(new VertexComparator());
orderedTaskSet.addAll(taskVertexSet);
TaskAttributes taskAttributes = new TaskAttributes();
int globalTaskIndex = 0;
for (Vertex vertex : taskVertexSet) {
int totalTaskInstances;
if (!graph.getNodeConstraints().isEmpty()) {
totalTaskInstances = taskAttributes.getTotalNumberOfInstances(vertex, graph.getNodeConstraints());
} else {
totalTaskInstances = taskAttributes.getTotalNumberOfInstances(vertex);
}
if (!graph.getNodeConstraints().isEmpty()) {
int instancesPerWorker = taskAttributes.getInstancesPerWorker(graph.getGraphConstraints());
int maxTaskInstancesPerContainer = 0;
int containerIndex;
for (int i = 0; i < totalTaskInstances; i++) {
containerIndex = i % numberOfContainers;
if (maxTaskInstancesPerContainer < instancesPerWorker) {
roundrobinAllocation.get(containerIndex).add(new TaskInstanceId(vertex.getName(), globalTaskIndex, i));
++maxTaskInstancesPerContainer;
} else {
throw new TaskSchedulerException("Task Scheduling couldn't be possible for the present" + "configuration, please check the number of workers, " + "maximum instances per worker");
}
}
} else {
String task = vertex.getName();
int containerIndex;
for (int i = 0; i < totalTaskInstances; i++) {
containerIndex = i % numberOfContainers;
roundrobinAllocation.get(containerIndex).add(new TaskInstanceId(task, globalTaskIndex, i));
}
}
globalTaskIndex++;
}
return roundrobinAllocation;
}
use of edu.iu.dsc.tws.api.compute.graph.Vertex 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);
}
Aggregations