[780] | 1 | package test; |
---|
| 2 | |
---|
| 3 | import java.util.Map; |
---|
| 4 | |
---|
| 5 | import schedframe.events.scheduling.SchedulingEvent; |
---|
| 6 | import schedframe.resources.units.PEUnit; |
---|
| 7 | import schedframe.resources.units.ResourceUnit; |
---|
| 8 | import schedframe.resources.units.ResourceUnitName; |
---|
| 9 | import schedframe.resources.units.StandardResourceUnitName; |
---|
| 10 | import dcworms.schedframe.scheduling.ExecTask; |
---|
[883] | 11 | import dcworms.schedframe.scheduling.Executable; |
---|
[780] | 12 | import example.timeestimation.BaseTimeEstimationPlugin; |
---|
| 13 | |
---|
| 14 | public 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) { |
---|
[883] | 28 | |
---|
[780] | 29 | |
---|
[883] | 30 | Executable exec = (Executable) task; |
---|
| 31 | // System.out.println(exec.getJobId() +":"+ exec.getApplicationName()); |
---|
[780] | 32 | // collect all information necessary to do the calculation |
---|
| 33 | PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE); |
---|
[883] | 34 | |
---|
[780] | 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 | } |
---|