Search in sources :

Example 16 with Vertex

use of edu.iu.dsc.tws.api.compute.graph.Vertex in project twister2 by DSC-SPIDAL.

the class GraphBuilder method addConfiguration.

public GraphBuilder addConfiguration(String taskName, String property, Object value) {
    Vertex v = graph.vertex(taskName);
    if (v == null) {
        throw new RuntimeException("Failed to add configuration to non-existing task: " + taskName);
    }
    v.addConfiguration(property, value);
    return this;
}
Also used : Vertex(edu.iu.dsc.tws.api.compute.graph.Vertex)

Example 17 with Vertex

use of edu.iu.dsc.tws.api.compute.graph.Vertex in project twister2 by DSC-SPIDAL.

the class ComputeGraphBuilder method addCompute.

/**
 * Add a compute node to the graph
 *
 * @param name name of the node
 * @param compute implementation of the node
 * @param parallel number of parallel instances
 * @return a compute connection, that can be used to connect this node to other nodes as a child
 */
public ComputeConnection addCompute(String name, ICompute compute, int parallel) {
    Vertex vertex = new Vertex(name, compute, parallel);
    nodes.put(name, vertex);
    this.addFTGatherSink(name);
    return createComputeConnection(name);
}
Also used : Vertex(edu.iu.dsc.tws.api.compute.graph.Vertex)

Example 18 with Vertex

use of edu.iu.dsc.tws.api.compute.graph.Vertex in project twister2 by DSC-SPIDAL.

the class ComputeGraphBuilder method addFTGatherSink.

private void addFTGatherSink(String sourceName) {
    if (!CheckpointingContext.isCheckpointingEnabled(cfg) || this.mode.equals(OperationMode.BATCH)) {
        return;
    }
    String ftTaskName = "ft-" + sourceName;
    Vertex vertex = new Vertex(ftTaskName, new CheckpointingSGatherSink(sourceName), 1);
    nodes.put(ftTaskName, vertex);
    ComputeConnection computeConnection = this.createComputeConnection(ftTaskName);
    computeConnection.gather(sourceName).withDataType(MessageTypes.LONG).viaEdge(CheckpointingSGatherSink.FT_GATHER_EDGE);
}
Also used : Vertex(edu.iu.dsc.tws.api.compute.graph.Vertex) CheckpointingSGatherSink(edu.iu.dsc.tws.checkpointing.task.CheckpointingSGatherSink)

Example 19 with Vertex

use of edu.iu.dsc.tws.api.compute.graph.Vertex in project twister2 by DSC-SPIDAL.

the class ComputeGraphBuilder method addSource.

/**
 * Add a source node to the graph
 *
 * @param name name of the node
 * @param source implementation of the node
 * @param parallel parallelism of the node
 * @return a compute connection, that can be used to connect this node to other nodes as a child
 */
public SourceConnection addSource(String name, ISource source, int parallel) {
    Vertex vertex = new Vertex(name, source, parallel);
    nodes.put(name, vertex);
    this.addFTGatherSink(name);
    return createSourceConnection(name);
}
Also used : Vertex(edu.iu.dsc.tws.api.compute.graph.Vertex)

Example 20 with Vertex

use of edu.iu.dsc.tws.api.compute.graph.Vertex 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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Vertex(edu.iu.dsc.tws.api.compute.graph.Vertex) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) TaskSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskSchedulePlan) WorkerSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan) TaskInstanceMapCalculation(edu.iu.dsc.tws.tsched.spi.taskschedule.TaskInstanceMapCalculation) TaskInstancePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan) Worker(edu.iu.dsc.tws.api.compute.schedule.elements.Worker) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Resource(edu.iu.dsc.tws.api.compute.schedule.elements.Resource) TaskInstanceId(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstanceId) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TaskVertexParser(edu.iu.dsc.tws.tsched.utils.TaskVertexParser)

Aggregations

Vertex (edu.iu.dsc.tws.api.compute.graph.Vertex)27 LinkedHashMap (java.util.LinkedHashMap)15 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)11 List (java.util.List)11 TaskInstanceId (edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstanceId)10 Map (java.util.Map)10 Resource (edu.iu.dsc.tws.api.compute.schedule.elements.Resource)8 TaskInstancePlan (edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan)8 TaskSchedulePlan (edu.iu.dsc.tws.api.compute.schedule.elements.TaskSchedulePlan)8 WorkerSchedulePlan (edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan)8 Config (edu.iu.dsc.tws.api.config.Config)8 LinkedHashSet (java.util.LinkedHashSet)8 Worker (edu.iu.dsc.tws.api.compute.schedule.elements.Worker)7 TaskInstanceMapCalculation (edu.iu.dsc.tws.tsched.spi.taskschedule.TaskInstanceMapCalculation)7 TreeSet (java.util.TreeSet)6 TaskSchedulerException (edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException)4 TaskAttributes (edu.iu.dsc.tws.tsched.utils.TaskAttributes)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4