use of edu.iu.dsc.tws.tsched.utils.TaskVertexParser in project twister2 by DSC-SPIDAL.
the class RoundRobinBatchTaskScheduler 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.
*/
@Override
public TaskSchedulePlan schedule(ComputeGraph computeGraph, WorkerPlan workerPlan) {
Map<Integer, List<TaskInstanceId>> containerInstanceMap;
Map<Integer, WorkerSchedulePlan> containerPlans = new LinkedHashMap<>();
for (int i = 0; i < workerPlan.getNumberOfWorkers(); i++) {
roundRobinAllocation.put(i, new ArrayList<>());
}
// To retrieve the batch task instances(it may be single task vertex or a batch of task vertices)
Set<Vertex> taskVertexSet = new LinkedHashSet<>(computeGraph.getTaskVertexSet());
TaskVertexParser taskGraphParser = new TaskVertexParser();
List<Set<Vertex>> taskVertexList = taskGraphParser.parseVertexSet(computeGraph);
for (Set<Vertex> vertexSet : taskVertexList) {
if (vertexSet.size() > 1) {
containerInstanceMap = roundRobinBatchSchedulingAlgorithm(computeGraph, vertexSet);
} else {
Vertex vertex = vertexSet.iterator().next();
containerInstanceMap = roundRobinBatchSchedulingAlgorithm(computeGraph, vertex);
}
TaskInstanceMapCalculation instanceMapCalculation = new TaskInstanceMapCalculation(this.instanceRAM, this.instanceCPU, this.instanceDisk);
Map<Integer, Map<TaskInstanceId, Double>> instancesRamMap = instanceMapCalculation.getInstancesRamMapInContainer(containerInstanceMap, taskVertexSet);
Map<Integer, Map<TaskInstanceId, Double>> instancesDiskMap = instanceMapCalculation.getInstancesDiskMapInContainer(containerInstanceMap, taskVertexSet);
Map<Integer, Map<TaskInstanceId, Double>> instancesCPUMap = instanceMapCalculation.getInstancesCPUMapInContainer(containerInstanceMap, taskVertexSet);
for (int containerId : containerInstanceMap.keySet()) {
double containerRAMValue = TaskSchedulerContext.containerRamPadding(config);
double containerDiskValue = TaskSchedulerContext.containerDiskPadding(config);
double containerCpuValue = TaskSchedulerContext.containerCpuPadding(config);
List<TaskInstanceId> taskTaskInstanceIds = containerInstanceMap.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;
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);
}
WorkerSchedulePlan taskWorkerSchedulePlan;
if (containerPlans.containsKey(containerId)) {
taskWorkerSchedulePlan = containerPlans.get(containerId);
taskWorkerSchedulePlan.getTaskInstances().addAll(taskInstancePlanMap.values());
} else {
taskWorkerSchedulePlan = new WorkerSchedulePlan(containerId, new HashSet<>(taskInstancePlanMap.values()), containerResource);
containerPlans.put(containerId, taskWorkerSchedulePlan);
}
}
}
return new TaskSchedulePlan(0, new HashSet<>(containerPlans.values()));
}
use of edu.iu.dsc.tws.tsched.utils.TaskVertexParser in project twister2 by DSC-SPIDAL.
the class DataLocalityBatchTaskScheduler method schedule.
/**
* This is the base method for the data locality aware task scheduling for scheduling the batch
* task instances. It retrieves the task vertex set of the task graph and send the set to the
* data locality aware scheduling algorithm to allocate the batch task instances which are closer
* to the data nodes.
*/
@Override
public TaskSchedulePlan schedule(ComputeGraph graph, WorkerPlan workerPlan) {
LinkedHashMap<Integer, WorkerSchedulePlan> containerPlans = new LinkedHashMap<>();
for (int i = 0; i < workerPlan.getNumberOfWorkers(); i++) {
dataLocalityAwareAllocation.put(i, new ArrayList<>());
}
LinkedHashSet<Vertex> taskVertexSet = new LinkedHashSet<>(graph.getTaskVertexSet());
TaskVertexParser taskVertexParser = new TaskVertexParser();
List<Set<Vertex>> taskVertexList = taskVertexParser.parseVertexSet(graph);
for (Set<Vertex> vertexSet : taskVertexList) {
Map<Integer, List<TaskInstanceId>> containerInstanceMap;
if (vertexSet.size() > 1) {
containerInstanceMap = dataLocalityBatchSchedulingAlgorithm(graph, vertexSet, workerPlan);
} else {
Vertex vertex = vertexSet.iterator().next();
containerInstanceMap = dataLocalityBatchSchedulingAlgorithm(graph, vertex, workerPlan);
}
TaskInstanceMapCalculation instanceMapCalculation = new TaskInstanceMapCalculation(this.instanceRAM, this.instanceCPU, this.instanceDisk);
Map<Integer, Map<TaskInstanceId, Double>> instancesRamMap = instanceMapCalculation.getInstancesRamMapInContainer(containerInstanceMap, taskVertexSet);
Map<Integer, Map<TaskInstanceId, Double>> instancesDiskMap = instanceMapCalculation.getInstancesDiskMapInContainer(containerInstanceMap, taskVertexSet);
Map<Integer, Map<TaskInstanceId, Double>> instancesCPUMap = instanceMapCalculation.getInstancesCPUMapInContainer(containerInstanceMap, taskVertexSet);
for (int containerId : containerInstanceMap.keySet()) {
double containerRAMValue = TaskSchedulerContext.containerRamPadding(config);
double containerDiskValue = TaskSchedulerContext.containerDiskPadding(config);
double containerCpuValue = TaskSchedulerContext.containerCpuPadding(config);
List<TaskInstanceId> taskTaskInstanceIds = containerInstanceMap.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;
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);
}
WorkerSchedulePlan taskWorkerSchedulePlan;
if (containerPlans.containsKey(containerId)) {
taskWorkerSchedulePlan = containerPlans.get(containerId);
taskWorkerSchedulePlan.getTaskInstances().addAll(taskInstancePlanMap.values());
} else {
taskWorkerSchedulePlan = new WorkerSchedulePlan(containerId, new HashSet<>(taskInstancePlanMap.values()), containerResource);
containerPlans.put(containerId, taskWorkerSchedulePlan);
}
}
}
TaskSchedulePlan taskSchedulePlan = new TaskSchedulePlan(0, new HashSet<>(containerPlans.values()));
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 + "\tsize:" + containerPlanTaskInstances.size());
for (TaskInstancePlan ip : containerPlanTaskInstances) {
LOG.fine("TaskId:" + ip.getTaskId() + "\tTask Index" + ip.getTaskIndex() + "\tTask Name:" + ip.getTaskName());
}
}
return taskSchedulePlan;
}
Aggregations