source: DCWoRMS/branches/coolemall/src/test/testSOP/BaseTimeEstimationPlugin.java @ 1606

Revision 1606, 2.5 KB checked in by wojtekp, 8 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.testSOP;
2
3import java.util.Map;
4
5import org.apache.commons.logging.Log;
6import org.apache.commons.logging.LogFactory;
7
8import dcworms.schedframe.scheduling.ExecTask;
9import schedframe.Parameters;
10import schedframe.PluginConfiguration;
11import schedframe.events.scheduling.SchedulingEvent;
12import schedframe.resources.units.PEUnit;
13import schedframe.resources.units.ResourceUnit;
14import schedframe.resources.units.ResourceUnitName;
15import schedframe.resources.units.StandardResourceUnitName;
16import schedframe.scheduling.plugin.estimation.ExecutionTimeEstimationPlugin;
17
18
19public class BaseTimeEstimationPlugin implements ExecutionTimeEstimationPlugin {
20        Log log = LogFactory.getLog(BaseTimeEstimationPlugin.class);
21        public PluginConfiguration getConfiguration() {
22                return null;
23        }
24
25        public String getName() {
26                return getClass().getName();
27        }
28
29        public void init(Parameters parameters) {
30        }
31
32        public double estimateMigrationTime(SchedulingEvent event, ExecTask task,
33                        Map<ResourceUnitName, ResourceUnit> srcResources, Map<ResourceUnitName, ResourceUnit> dstResources) {
34                double time = 0;
35                //Test migration 10s
36//              log.debug("Migration takes "+time+" seconds.");
37                return time;
38        }
39
40        /*
41         * This method should return an estimation of time required to execute the task.
42         * Requested calculation should be done based on the resources allocated for the task,
43         * task description and task completion percentage.
44         *
45         * Example implementation calculate the estimation based on cpu processing power.
46         * There is also a simple assumption, that cpu processing power is a linear function
47         * of number of allocated cpus and their speed.
48         */
49        public double execTimeEstimation(SchedulingEvent event, ExecTask task,
50                        Map<ResourceUnitName, ResourceUnit> allocatedResources,
51                        double completionPercentage) {
52               
53                // collect all information necessary to do the calculation
54                PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE);
55
56                // obtain single pe speed
57                int speed = peUnit.getSpeed();
58
59                // number of used pe 
60                int cnt = peUnit.getUsedAmount();
61
62                // estimate remainingTaskLength
63                double remainingLength =  task.getLength() * (1 - completionPercentage/100);
64               
65                // do the calculation
66                double execTime = (remainingLength / (cnt * speed));
67
68                // if the result is very close to 0, but less then one millisecond then round this result to 0.001
69                if (Double.compare(execTime, 0.001) < 0) {
70                        execTime = 0.001;
71                }
72
73                // time is measured in integer units, so get the nearest execTime int value.
74                execTime = Math.round(execTime);
75                return execTime;
76        }
77
78       
79}
Note: See TracBrowser for help on using the repository browser.