source: DCWoRMS/trunk/src/test/article/recs/plugins/timeestimation/RecsTimeEstimationPlugin.java @ 656

Revision 656, 3.7 KB checked in by wojtekp, 12 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.article.recs.plugins.timeestimation;
2
3import java.io.FileInputStream;
4import java.io.FileNotFoundException;
5import java.io.IOException;
6import java.util.Map;
7import java.util.MissingResourceException;
8import java.util.PropertyResourceBundle;
9import java.util.Random;
10import java.util.ResourceBundle;
11
12import schedframe.events.scheduling.SchedulingEvent;
13import schedframe.resources.computing.Core;
14import schedframe.resources.computing.Processor;
15import schedframe.resources.units.PEUnit;
16import schedframe.resources.units.ProcessingElements;
17import schedframe.resources.units.ResourceUnit;
18import schedframe.resources.units.ResourceUnitName;
19import schedframe.resources.units.StandardResourceUnitName;
20import test.article.recs.utils.AppType;
21import test.article.recs.utils.TaskToApp;
22import dcworms.schedframe.scheduling.ExecTask;
23import example.timeestimation.BaseTimeEstimationPlugin;
24
25public 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       
30        private TaskToApp taskToApp = new TaskToApp();
31
32        public double execTimeEstimation(SchedulingEvent event, ExecTask task,
33                        Map<ResourceUnitName, ResourceUnit> allocatedResources,
34                        double completionPercentage) {
35               
36                double execTime;
37               
38                PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE);
39               
40                String query = createQuery(task, peUnit);
41                try {
42                        execTime = TIME_FACTOR * (1 - completionPercentage/100) * getMeasuredTime(query);
43                        if (Double.compare(execTime, 0.001) < 0) {
44                                execTime = 0.001;
45                        }
46                        execTime = Math.round(execTime);
47                } catch (FileNotFoundException e) {
48                        execTime = defaultEstimation(task, peUnit, completionPercentage);
49                } catch (IOException e) {
50                        execTime = defaultEstimation(task, peUnit, completionPercentage);
51                } catch(MissingResourceException e){
52                        execTime = defaultEstimation(task, peUnit, completionPercentage);
53                }
54
55                return execTime;
56        }
57
58        private String createQuery(ExecTask task, PEUnit peUnit) {
59                String query;
60                query = getApplicationType(task) + "." + getNodeCategory(peUnit) + "." + getFrequency(peUnit) + "." + getCoreCnt(task);
61                return query;
62        }
63
64        private String getApplicationType(ExecTask task){       
65                AppType appType = taskToApp.getAppType(task);
66                return appType.toString();
67        }
68       
69        private String getNodeCategory(PEUnit peUnit){
70               
71                ProcessingElements pe = (ProcessingElements) peUnit;
72                Core core = (Core)pe.get(0);
73                return core.getParent().getParent().getCategory();
74        }
75       
76        private int getFrequency(PEUnit peUnit){
77                ProcessingElements pe = (ProcessingElements) peUnit;
78                Core core = (Core)pe.get(0);
79                Processor proc = (Processor) core.getParent();
80                double freq;
81                try{
82                        freq = proc.getPowerInterface().getFrequency();
83                } catch(Exception e){
84                        freq = 800;
85                }
86                return Double.valueOf(freq).intValue();
87               
88        }
89       
90        private int getCoreCnt(ExecTask task){ 
91                double cpuReq;
92                try {
93                        cpuReq = task.getCpuCntRequest();
94                } catch (NoSuchFieldException e) {
95                                cpuReq = 1;
96                }
97                return Double.valueOf(cpuReq).intValue();
98        }
99       
100        private double getMeasuredTime(String query) throws FileNotFoundException, IOException{
101                ResourceBundle bundle = new PropertyResourceBundle(new FileInputStream(TIME_DATA_FILE_NAME));
102                return Double.valueOf(bundle.getString(query)).doubleValue();
103        }
104
105        private double defaultEstimation(ExecTask task,
106                        PEUnit peUnit,
107                        double completionPercentage){
108                int speed = peUnit.getSpeed();
109                int cnt = peUnit.getUsedAmount();
110
111                double remainingLength =  task.getLength() * (1 - completionPercentage/100);
112               
113                double execTime = (remainingLength / (cnt * speed));
114                if (Double.compare(execTime, 0.001) < 0) {
115                        execTime = 0.001;
116                }
117                execTime = Math.round(execTime);
118                return execTime;
119        }
120}
121
122
Note: See TracBrowser for help on using the repository browser.