package test.article2.recs.plugins.timeestimation; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Map; import java.util.MissingResourceException; import java.util.PropertyResourceBundle; import java.util.ResourceBundle; import schedframe.events.scheduling.SchedulingEvent; import schedframe.resources.computing.ComputingNode; import schedframe.resources.computing.Core; import schedframe.resources.computing.Processor; import schedframe.resources.units.PEUnit; import schedframe.resources.units.ProcessingElements; import schedframe.resources.units.ResourceUnit; import schedframe.resources.units.ResourceUnitName; import schedframe.resources.units.StandardResourceUnitName; import test.article2.recs.utils.AppType; import test.article2.recs.utils.TaskToApp; import dcworms.schedframe.scheduling.ExecTask; import example.timeestimation.BaseTimeEstimationPlugin; public class RecsTimeEstimationPlugin extends BaseTimeEstimationPlugin{ private static String TIME_DATA_FILE_NAME = "src/test/article2/recs/data/time_data.properties"; private static int TIME_FACTOR = 1; private ResourceBundle timeBundle; private TaskToApp taskToApp = new TaskToApp(); public double execTimeEstimation(SchedulingEvent event, ExecTask task, Map allocatedResources, double completionPercentage) { double execTime; PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE); String query = createQuery(task, peUnit); try { execTime = TIME_FACTOR * (1 - completionPercentage/100) * getMeasuredTime(query); //System.out.println(task.getJobId()+": "+ execTime + "; "+ completionPercentage); if (Double.compare(execTime, 0.001) < 0) { execTime = 0.001; } execTime = Math.round(execTime); //System.out.println(task.getJobId()+": "+ execTime); } catch (FileNotFoundException e) { execTime = defaultEstimation(task, peUnit, completionPercentage); } catch (IOException e) { execTime = defaultEstimation(task, peUnit, completionPercentage); } catch(MissingResourceException e){ execTime = defaultEstimation(task, peUnit, completionPercentage); } execTime = defaultEstimation(task, peUnit, completionPercentage); return execTime; } private String createQuery(ExecTask task, PEUnit peUnit) { String query; query = getApplicationType(task) + "." + getNodeCategory(peUnit) + "." + getFrequency(peUnit) + "." + getLoad(task); return query; } private String getApplicationType(ExecTask task){ AppType appType = taskToApp.getAppType(task); return appType.toString(); } private String getNodeCategory(PEUnit peUnit){ ProcessingElements pe = (ProcessingElements) peUnit; if(pe.get(0) instanceof ComputingNode) return ((ComputingNode)pe.get(0)).getCategory(); if(pe.get(0) instanceof Processor) return ((Processor)pe.get(0)).getParent().getCategory(); Core core = (Core)pe.get(0); return core.getParent().getParent().getCategory(); } private int getFrequency(PEUnit peUnit){ ProcessingElements pe = (ProcessingElements) peUnit; if(pe.get(0) instanceof ComputingNode) return Double.valueOf(((ComputingNode)pe.get(0)).getProcessors().get(0).getPowerInterface().getFrequency()).intValue(); if(pe.get(0) instanceof Processor) return Double.valueOf(((Processor)pe.get(0)).getPowerInterface().getFrequency()).intValue(); Core core = (Core)pe.get(0); Processor proc = (Processor) core.getParent(); double freq = proc.getPowerInterface().getFrequency(); return Double.valueOf(freq).intValue(); } private int getLoad(ExecTask task){ double load = 1; return Double.valueOf(load).intValue(); } private double getMeasuredTime(String query) throws FileNotFoundException, IOException{ ResourceBundle timeBundle = getTimeBundle(); return Double.valueOf(timeBundle.getString(query)).doubleValue(); } private ResourceBundle getTimeBundle() throws FileNotFoundException, IOException{ if(timeBundle == null){ timeBundle = new PropertyResourceBundle(new FileInputStream(TIME_DATA_FILE_NAME)); } return timeBundle; } private double defaultEstimation(ExecTask task, PEUnit peUnit, double completionPercentage){ int speed = peUnit.getSpeed(); int cnt = peUnit.getUsedAmount(); double remainingLength = task.getLength() * (1 - completionPercentage/100); double execTime = (remainingLength / (cnt * speed)); if (Double.compare(execTime, 0.001) < 0) { execTime = 0.001; } execTime = Math.round(execTime); return execTime; } }