source: DCWoRMS/trunk/src/test/article2/recs/plugins/timeestimation/RecsTimeEstimationPlugin.java @ 826

Revision 826, 4.5 KB checked in by wojtekp, 12 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.article2.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.article2.recs.utils.AppType;
21import test.article2.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/article2/recs/data/time_data.properties";
28        private static int TIME_FACTOR = 1;
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                execTime = defaultEstimation(task, peUnit, completionPercentage);
59                return execTime;
60        }
61
62        private String createQuery(ExecTask task, PEUnit peUnit) {
63                String query;
64                query = getApplicationType(task) + "." + getNodeCategory(peUnit) + "." + getFrequency(peUnit) + "." + getLoad(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                if(pe.get(0) instanceof Processor)
79                        return ((Processor)pe.get(0)).getParent().getCategory();
80                Core core = (Core)pe.get(0);
81                return core.getParent().getParent().getCategory();
82        }
83       
84        private int getFrequency(PEUnit peUnit){
85                ProcessingElements pe = (ProcessingElements) peUnit;
86                if(pe.get(0) instanceof ComputingNode)
87                        return Double.valueOf(((ComputingNode)pe.get(0)).getProcessors().get(0).getPowerInterface().getFrequency()).intValue();
88                if(pe.get(0) instanceof Processor)
89                        return Double.valueOf(((Processor)pe.get(0)).getPowerInterface().getFrequency()).intValue();
90                Core core = (Core)pe.get(0);
91                Processor proc = (Processor) core.getParent();
92                double freq = proc.getPowerInterface().getFrequency();
93
94                return Double.valueOf(freq).intValue();
95               
96        }
97       
98        private int getLoad(ExecTask task){     
99                double load = 1;
100                return Double.valueOf(load).intValue();
101        }
102       
103        private double getMeasuredTime(String query) throws FileNotFoundException, IOException{
104                ResourceBundle timeBundle = getTimeBundle();
105                return Double.valueOf(timeBundle.getString(query)).doubleValue();
106        }
107
108        private ResourceBundle getTimeBundle() throws FileNotFoundException, IOException{
109                if(timeBundle == null){
110                        timeBundle = new PropertyResourceBundle(new FileInputStream(TIME_DATA_FILE_NAME));
111                }
112                return timeBundle;
113        }
114
115        private double defaultEstimation(ExecTask task,
116                        PEUnit peUnit,
117                        double completionPercentage){
118                int speed = peUnit.getSpeed();
119                int cnt = peUnit.getUsedAmount();
120
121                double remainingLength =  task.getLength() * (1 - completionPercentage/100);
122               
123                double execTime = (remainingLength / (cnt * speed));
124                if (Double.compare(execTime, 0.001) < 0) {
125                        execTime = 0.001;
126                }
127                execTime = Math.round(execTime);
128                return execTime;
129        }
130}
131
132
Note: See TracBrowser for help on using the repository browser.