[656] | 1 | package test.article.recs.plugins.timeestimation; |
---|
| 2 | |
---|
| 3 | import java.io.FileInputStream; |
---|
| 4 | import java.io.FileNotFoundException; |
---|
| 5 | import java.io.IOException; |
---|
| 6 | import java.util.Map; |
---|
| 7 | import java.util.MissingResourceException; |
---|
| 8 | import java.util.PropertyResourceBundle; |
---|
| 9 | import java.util.ResourceBundle; |
---|
| 10 | |
---|
| 11 | import schedframe.events.scheduling.SchedulingEvent; |
---|
[734] | 12 | import schedframe.resources.computing.ComputingNode; |
---|
[656] | 13 | import schedframe.resources.computing.Core; |
---|
| 14 | import schedframe.resources.computing.Processor; |
---|
| 15 | import schedframe.resources.units.PEUnit; |
---|
| 16 | import schedframe.resources.units.ProcessingElements; |
---|
| 17 | import schedframe.resources.units.ResourceUnit; |
---|
| 18 | import schedframe.resources.units.ResourceUnitName; |
---|
| 19 | import schedframe.resources.units.StandardResourceUnitName; |
---|
| 20 | import test.article.recs.utils.AppType; |
---|
| 21 | import test.article.recs.utils.TaskToApp; |
---|
| 22 | import dcworms.schedframe.scheduling.ExecTask; |
---|
| 23 | import example.timeestimation.BaseTimeEstimationPlugin; |
---|
| 24 | |
---|
| 25 | public class RecsTimeEstimationPlugin extends BaseTimeEstimationPlugin{ |
---|
| 26 | |
---|
| 27 | private static String TIME_DATA_FILE_NAME = "src/test/article/recs/data/time_data.properties"; |
---|
| 28 | private static int TIME_FACTOR = 20; |
---|
| 29 | |
---|
[661] | 30 | private ResourceBundle timeBundle; |
---|
| 31 | |
---|
[656] | 32 | private TaskToApp taskToApp = new TaskToApp(); |
---|
| 33 | |
---|
| 34 | public double execTimeEstimation(SchedulingEvent event, ExecTask task, |
---|
| 35 | Map<ResourceUnitName, ResourceUnit> allocatedResources, |
---|
| 36 | double completionPercentage) { |
---|
| 37 | |
---|
| 38 | double execTime; |
---|
| 39 | |
---|
| 40 | PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE); |
---|
| 41 | |
---|
| 42 | String query = createQuery(task, peUnit); |
---|
| 43 | try { |
---|
| 44 | execTime = TIME_FACTOR * (1 - completionPercentage/100) * getMeasuredTime(query); |
---|
[734] | 45 | //System.out.println(task.getJobId()+": "+ execTime + "; "+ completionPercentage); |
---|
[656] | 46 | if (Double.compare(execTime, 0.001) < 0) { |
---|
| 47 | execTime = 0.001; |
---|
| 48 | } |
---|
| 49 | execTime = Math.round(execTime); |
---|
[734] | 50 | //System.out.println(task.getJobId()+": "+ execTime); |
---|
[656] | 51 | } catch (FileNotFoundException e) { |
---|
| 52 | execTime = defaultEstimation(task, peUnit, completionPercentage); |
---|
| 53 | } catch (IOException e) { |
---|
| 54 | execTime = defaultEstimation(task, peUnit, completionPercentage); |
---|
| 55 | } catch(MissingResourceException e){ |
---|
| 56 | execTime = defaultEstimation(task, peUnit, completionPercentage); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | return execTime; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | private String createQuery(ExecTask task, PEUnit peUnit) { |
---|
| 63 | String query; |
---|
| 64 | query = getApplicationType(task) + "." + getNodeCategory(peUnit) + "." + getFrequency(peUnit) + "." + getCoreCnt(task); |
---|
| 65 | return query; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | private String getApplicationType(ExecTask task){ |
---|
| 69 | AppType appType = taskToApp.getAppType(task); |
---|
| 70 | return appType.toString(); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | private String getNodeCategory(PEUnit peUnit){ |
---|
| 74 | |
---|
| 75 | ProcessingElements pe = (ProcessingElements) peUnit; |
---|
[734] | 76 | if(pe.get(0) instanceof ComputingNode) |
---|
| 77 | return ((ComputingNode)pe.get(0)).getCategory(); |
---|
[656] | 78 | Core core = (Core)pe.get(0); |
---|
| 79 | return core.getParent().getParent().getCategory(); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | private int getFrequency(PEUnit peUnit){ |
---|
| 83 | ProcessingElements pe = (ProcessingElements) peUnit; |
---|
[734] | 84 | if(pe.get(0) instanceof ComputingNode) |
---|
| 85 | return Double.valueOf(((ComputingNode)pe.get(0)).getProcessors().get(0).getPowerInterface().getFrequency()).intValue(); |
---|
[656] | 86 | Core core = (Core)pe.get(0); |
---|
| 87 | Processor proc = (Processor) core.getParent(); |
---|
[664] | 88 | double freq = proc.getPowerInterface().getFrequency(); |
---|
| 89 | |
---|
[656] | 90 | return Double.valueOf(freq).intValue(); |
---|
| 91 | |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | private int getCoreCnt(ExecTask task){ |
---|
| 95 | double cpuReq; |
---|
| 96 | try { |
---|
| 97 | cpuReq = task.getCpuCntRequest(); |
---|
| 98 | } catch (NoSuchFieldException e) { |
---|
| 99 | cpuReq = 1; |
---|
| 100 | } |
---|
| 101 | return Double.valueOf(cpuReq).intValue(); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | private double getMeasuredTime(String query) throws FileNotFoundException, IOException{ |
---|
[661] | 105 | ResourceBundle timeBundle = getTimeBundle(); |
---|
| 106 | return Double.valueOf(timeBundle.getString(query)).doubleValue(); |
---|
[656] | 107 | } |
---|
| 108 | |
---|
[661] | 109 | private ResourceBundle getTimeBundle() throws FileNotFoundException, IOException{ |
---|
| 110 | if(timeBundle == null){ |
---|
| 111 | timeBundle = new PropertyResourceBundle(new FileInputStream(TIME_DATA_FILE_NAME)); |
---|
| 112 | } |
---|
| 113 | return timeBundle; |
---|
| 114 | } |
---|
| 115 | |
---|
[656] | 116 | private double defaultEstimation(ExecTask task, |
---|
| 117 | PEUnit peUnit, |
---|
| 118 | double completionPercentage){ |
---|
| 119 | int speed = peUnit.getSpeed(); |
---|
| 120 | int cnt = peUnit.getUsedAmount(); |
---|
| 121 | |
---|
| 122 | double remainingLength = task.getLength() * (1 - completionPercentage/100); |
---|
| 123 | |
---|
| 124 | double execTime = (remainingLength / (cnt * speed)); |
---|
| 125 | if (Double.compare(execTime, 0.001) < 0) { |
---|
| 126 | execTime = 0.001; |
---|
| 127 | } |
---|
| 128 | execTime = Math.round(execTime); |
---|
| 129 | return execTime; |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | |
---|