source: DCWoRMS/branches/coolemall/src/test/drs_tst/recs/plugins/timeestimation/RecsTimeEstimationPlugin.java @ 1247

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