source: DCWoRMS/branches/coolemall/src/test/PhaseTimeEstimationPlugin.java @ 883

Revision 883, 2.0 KB checked in by wojtekp, 12 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test;
2
3import java.util.Map;
4
5import schedframe.events.scheduling.SchedulingEvent;
6import schedframe.resources.units.PEUnit;
7import schedframe.resources.units.ResourceUnit;
8import schedframe.resources.units.ResourceUnitName;
9import schedframe.resources.units.StandardResourceUnitName;
10import dcworms.schedframe.scheduling.ExecTask;
11import dcworms.schedframe.scheduling.Executable;
12import example.timeestimation.BaseTimeEstimationPlugin;
13
14public class PhaseTimeEstimationPlugin extends BaseTimeEstimationPlugin{
15
16        /*
17         * This method should return an estimation of time required to execute the task.
18         * Requested calculation should be done based on the resources allocated for the task,
19         * task description and task completion percentage.
20         *
21         * Example implementation calculate the estimation based on cpu processing power.
22         * There is also a simple assumption, that cpu processing power is a linear function
23         * of number of allocated cpus and their speed.
24         */
25        public double execTimeEstimation(SchedulingEvent event, ExecTask task,
26                        Map<ResourceUnitName, ResourceUnit> allocatedResources,
27                        double completionPercentage) {
28
29               
30                Executable exec = (Executable) task;
31        //      System.out.println(exec.getJobId() +":"+ exec.getApplicationName());
32                // collect all information necessary to do the calculation
33                PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE);
34               
35                // obtain single pe speed
36                int speed = peUnit.getSpeed();
37
38                // number of used pe 
39                int cnt = peUnit.getUsedAmount();
40
41                // estimate remainingTaskLength
42                double remainingLength =  task.getLength() * (1 - completionPercentage/100);
43               
44                // do the calculation
45                double execTime = (remainingLength / (cnt * speed));
46
47                // if the result is very close to 0, but less then one millisecond then round this result to 0.001
48                if (Double.compare(execTime, 0.001) < 0) {
49                        execTime = 0.001;
50                }
51
52                // time is measured in integer units, so get the nearest execTime int value.
53                execTime = Math.round(execTime);
54                return execTime;
55        }
56
57}
Note: See TracBrowser for help on using the repository browser.