source: DCWoRMS/branches/coolemall/src/test/cpusharing/CPUSharingTimeEstimationPlugin.java @ 1393

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