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

Revision 734, 4.3 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.ComputingNode;
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 ResourceBundle timeBundle;
31       
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);
45                        //System.out.println(task.getJobId()+": "+ execTime + "; "+ completionPercentage);
46                        if (Double.compare(execTime, 0.001) < 0) {
47                                execTime = 0.001;
48                        }
49                        execTime = Math.round(execTime);
50                        //System.out.println(task.getJobId()+": "+ execTime);
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;
76                if(pe.get(0) instanceof ComputingNode)
77                        return ((ComputingNode)pe.get(0)).getCategory();
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;
84                if(pe.get(0) instanceof ComputingNode)
85                        return Double.valueOf(((ComputingNode)pe.get(0)).getProcessors().get(0).getPowerInterface().getFrequency()).intValue();
86                Core core = (Core)pe.get(0);
87                Processor proc = (Processor) core.getParent();
88                double freq = proc.getPowerInterface().getFrequency();
89
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{
105                ResourceBundle timeBundle = getTimeBundle();
106                return Double.valueOf(timeBundle.getString(query)).doubleValue();
107        }
108
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
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
Note: See TracBrowser for help on using the repository browser.