Search in sources :

Example 1 with InstanceId

use of edu.iu.dsc.tws.tsched.spi.taskschedule.InstanceId in project twister2 by DSC-SPIDAL.

the class RRTaskScheduling method RoundRobinScheduling.

/**
 * This method is to perform the Round Robin based Scheduling operation.
 * And, it will allocate the instances in a Round Robin mode.
 *
 * @return Container Instance Map
 */
private Map<Integer, List<InstanceId>> RoundRobinScheduling() {
    int taskIndex = 1;
    int globalTaskIndex = 1;
    Job job = new Job();
    job = job.getJob();
    Map<Integer, List<InstanceId>> roundRobinAllocation = new HashMap<>();
    try {
        int numberOfContainers = JobAttributes.getNumberOfContainers(job);
        int totalInstances = JobAttributes.getTotalNumberOfInstances(job);
        for (int i = 1; i <= numberOfContainers; i++) {
            roundRobinAllocation.put(i, new ArrayList<InstanceId>());
        }
        Map<String, Integer> parallelTaskMap = JobAttributes.getParallelTaskMap(job);
        for (String task : parallelTaskMap.keySet()) {
            int numberOfInstances = parallelTaskMap.get(task);
            for (int i = 0; i < numberOfInstances; i++) {
                roundRobinAllocation.get(taskIndex).add(new InstanceId(task, globalTaskIndex, i));
                if (taskIndex != numberOfContainers) {
                    taskIndex = taskIndex + 1;
                } else {
                    taskIndex = 1;
                }
                globalTaskIndex += 1;
            }
        }
    } catch (NullPointerException ne) {
        ne.printStackTrace();
    }
    return roundRobinAllocation;
}
Also used : HashMap(java.util.HashMap) InstanceId(edu.iu.dsc.tws.tsched.spi.taskschedule.InstanceId) ArrayList(java.util.ArrayList) List(java.util.List) Job(edu.iu.dsc.tws.tsched.utils.Job)

Example 2 with InstanceId

use of edu.iu.dsc.tws.tsched.spi.taskschedule.InstanceId in project twister2 by DSC-SPIDAL.

the class RoundRobinScheduling method RoundRobinSchedulingAlgorithm.

// public static Map<Integer, List<InstanceId>> RoundRobinSchedulingAlgorithm() {
public static Map<Integer, List<InstanceId>> RoundRobinSchedulingAlgorithm(Job job) {
    int taskIndex = 1;
    int globalTaskIndex = 1;
    // Job job = new Job();
    // job = job.getJob();
    Map<Integer, List<InstanceId>> roundrobinAllocation = new HashMap<>();
    try {
        int numberOfContainers = JobAttributes.getNumberOfContainers(job);
        int totalInstances = JobAttributes.getTotalNumberOfInstances(job);
        LOG.info("Number of Containers:" + numberOfContainers + "\t" + "number of instances:" + totalInstances);
        for (int i = 1; i <= numberOfContainers; i++) {
            roundrobinAllocation.put(i, new ArrayList<InstanceId>());
        }
        LOG.info("RR Map Before Allocation\t" + roundrobinAllocation);
        // This value will be replaced with the actual job attributes
        Map<String, Integer> parallelTaskMap = JobAttributes.getParallelTaskMap(job);
        for (String task : parallelTaskMap.keySet()) {
            int numberOfInstances = parallelTaskMap.get(task);
            LOG.info("Task name:" + task + "\t" + "and number of instances:\t" + numberOfInstances);
            for (int i = 0; i < numberOfInstances; i++) {
                roundrobinAllocation.get(taskIndex).add(new InstanceId(task, globalTaskIndex, i));
                if (taskIndex != numberOfContainers) {
                    taskIndex = taskIndex + 1;
                } else {
                    taskIndex = 1;
                }
                LOG.info("Task index and number of containers:\t" + taskIndex + "\t" + numberOfContainers);
                globalTaskIndex += 1;
            }
        }
        LOG.info("RR Map After Allocation\t" + roundrobinAllocation);
    } catch (NullPointerException ne) {
        ne.printStackTrace();
    }
    return roundrobinAllocation;
}
Also used : HashMap(java.util.HashMap) InstanceId(edu.iu.dsc.tws.tsched.spi.taskschedule.InstanceId) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with InstanceId

use of edu.iu.dsc.tws.tsched.spi.taskschedule.InstanceId in project twister2 by DSC-SPIDAL.

the class RRTaskScheduling method getInstancesRamMapInContainer.

private Map<Integer, Map<InstanceId, Double>> getInstancesRamMapInContainer(Map<Integer, List<InstanceId>> containerInstanceAllocationMap) {
    Map<String, Double> ramMap = JobAttributes.getTaskRamMap(this.jobObject);
    Map<Integer, Map<InstanceId, Double>> instancesRamContainerMap = new HashMap<>();
    for (int containerId : containerInstanceAllocationMap.keySet()) {
        Double usedRamValue = 0.0;
        List<InstanceId> instanceIds = containerInstanceAllocationMap.get(containerId);
        Map<InstanceId, Double> containerRam = new HashMap<>();
        instancesRamContainerMap.put(containerId, containerRam);
        List<InstanceId> instancesToBeCalculated = new ArrayList<>();
        for (InstanceId instanceId : instanceIds) {
            String taskName = instanceId.getTaskName();
            if (ramMap.containsKey(taskName)) {
                Double ramValue = ramMap.get(taskName);
                containerRam.put(instanceId, ramValue);
            } else {
                instancesToBeCalculated.add(instanceId);
            }
        }
        Double containerRamValue = getContainerRamValue(containerInstanceAllocationMap);
        int instancesAllocationSize = instancesToBeCalculated.size();
        if (instancesAllocationSize != 0) {
            Double instanceRequiredRam = instanceRAM;
            if (!containerRamValue.equals(NOT_SPECIFIED_NUMBER_VALUE)) {
                Double remainingRam = containerRamValue - DEFAULT_RAM_PADDING_PER_CONTAINER - usedRamValue;
                instanceRequiredRam = remainingRam / instancesAllocationSize;
            }
            for (InstanceId instanceId : instancesToBeCalculated) {
                containerRam.put(instanceId, instanceRequiredRam);
            }
        }
    }
    return instancesRamContainerMap;
}
Also used : HashMap(java.util.HashMap) InstanceId(edu.iu.dsc.tws.tsched.spi.taskschedule.InstanceId) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with InstanceId

use of edu.iu.dsc.tws.tsched.spi.taskschedule.InstanceId in project twister2 by DSC-SPIDAL.

the class RRTaskScheduling method getInstancesDiskMapInContainer.

private Map<Integer, Map<InstanceId, Double>> getInstancesDiskMapInContainer(Map<Integer, List<InstanceId>> containerInstanceAllocationMap) {
    Map<String, Double> diskMap = JobAttributes.getTaskDiskMap(this.jobObject);
    Map<Integer, Map<InstanceId, Double>> instancesDiskContainerMap = new HashMap<>();
    for (int containerId : containerInstanceAllocationMap.keySet()) {
        Double usedDiskValue = 0.0;
        List<InstanceId> instanceIds = containerInstanceAllocationMap.get(containerId);
        Map<InstanceId, Double> containerDisk = new HashMap<>();
        instancesDiskContainerMap.put(containerId, containerDisk);
        List<InstanceId> instancesToBeCalculated = new ArrayList<>();
        for (InstanceId instanceId : instanceIds) {
            String taskName = instanceId.getTaskName();
            if (diskMap.containsKey(taskName)) {
                Double diskValue = diskMap.get(taskName);
                containerDisk.put(instanceId, diskValue);
            } else {
                instancesToBeCalculated.add(instanceId);
            }
        }
        Double containerDiskValue = getContainerDiskValue(containerInstanceAllocationMap);
        int instancesAllocationSize = instancesToBeCalculated.size();
        if (instancesAllocationSize != 0) {
            Double instanceRequiredDisk = 0.0;
            if (!containerDiskValue.equals(NOT_SPECIFIED_NUMBER_VALUE)) {
                Double remainingDisk = containerDiskValue - DEFAULT_DISK_PADDING_PER_CONTAINER - usedDiskValue;
                instanceRequiredDisk = remainingDisk / instancesAllocationSize;
            }
            for (InstanceId instanceId : instancesToBeCalculated) {
                containerDisk.put(instanceId, instanceRequiredDisk);
            }
            System.out.println("Instances Required Disk:\t" + instanceRequiredDisk);
        }
    }
    return instancesDiskContainerMap;
}
Also used : HashMap(java.util.HashMap) InstanceId(edu.iu.dsc.tws.tsched.spi.taskschedule.InstanceId) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with InstanceId

use of edu.iu.dsc.tws.tsched.spi.taskschedule.InstanceId in project twister2 by DSC-SPIDAL.

the class RRTaskScheduling method tschedule.

/**
 * This method invokes the Round Robin Scheduling Method and fetch the container instance allocation map.
 * Using the map value it calculates the required ram, disk, and cpu percentage for
 * each container and instances in each container and generates the task schedule plan
 * for those instances and the containers.
 */
@Override
public TaskSchedulePlan tschedule() {
    Map<Integer, List<InstanceId>> roundRobinContainerInstanceMap = RoundRobinScheduling();
    Set<TaskSchedulePlan.ContainerPlan> containerPlans = new HashSet<>();
    double containerCPUValue = getContainerCPUValue(roundRobinContainerInstanceMap);
    double containerRAMValue = getContainerRamValue(roundRobinContainerInstanceMap);
    double containerDiskValue = getContainerDiskValue(roundRobinContainerInstanceMap);
    for (Integer containerId : roundRobinContainerInstanceMap.keySet()) {
        List<InstanceId> taskInstanceIds = roundRobinContainerInstanceMap.get(containerId);
        Map<InstanceId, TaskSchedulePlan.TaskInstancePlan> taskInstancePlanMap = new HashMap<>();
        for (InstanceId id : taskInstanceIds) {
            double instanceCPUValue = instanceCPU;
            double instanceRAMValue = instanceRAM;
            double instanceDiskValue = instanceDisk;
            Resource resource = new Resource(instanceRAM, instanceDisk, instanceCPU);
            taskInstancePlanMap.put(id, new TaskSchedulePlan.TaskInstancePlan("mpitask", 1, 1, resource));
        }
        Resource resource = new Resource(containerRAMValue, containerDiskValue, containerCPUValue);
        TaskSchedulePlan.ContainerPlan taskContainerPlan = new TaskSchedulePlan.ContainerPlan(containerId, new HashSet<>(taskInstancePlanMap.values()), resource);
        containerPlans.add(taskContainerPlan);
    }
    return new TaskSchedulePlan(jobObject.getJobId(), containerPlans);
}
Also used : InstanceId(edu.iu.dsc.tws.tsched.spi.taskschedule.InstanceId) HashMap(java.util.HashMap) Resource(edu.iu.dsc.tws.tsched.spi.taskschedule.Resource) TaskSchedulePlan(edu.iu.dsc.tws.tsched.spi.taskschedule.TaskSchedulePlan) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

InstanceId (edu.iu.dsc.tws.tsched.spi.taskschedule.InstanceId)6 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)5 List (java.util.List)4 Map (java.util.Map)3 Resource (edu.iu.dsc.tws.tsched.spi.taskschedule.Resource)2 TaskSchedulePlan (edu.iu.dsc.tws.tsched.spi.taskschedule.TaskSchedulePlan)2 HashSet (java.util.HashSet)2 InstanceMapCalculation (edu.iu.dsc.tws.tsched.spi.taskschedule.InstanceMapCalculation)1 Job (edu.iu.dsc.tws.tsched.utils.Job)1