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

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