[477] | 1 | package example.timeestimation; |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | import java.util.Map; |
---|
| 5 | |
---|
[490] | 6 | import dcworms.schedframe.scheduling.ExecTask; |
---|
| 7 | |
---|
[477] | 8 | import schedframe.events.scheduling.SchedulingEvent; |
---|
| 9 | import schedframe.resources.units.PEUnit; |
---|
| 10 | import schedframe.resources.units.ResourceUnit; |
---|
| 11 | import schedframe.resources.units.ResourceUnitName; |
---|
| 12 | import schedframe.resources.units.StandardResourceUnitName; |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | /** |
---|
| 16 | * |
---|
| 17 | * @author Marcin Krystek && Wojciech Piatek |
---|
| 18 | * |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | public class DefaultTimeEstimationPlugin extends BaseTimeEstimationPlugin{ |
---|
| 22 | |
---|
| 23 | /* |
---|
| 24 | * This method should return an estimation of time required to execute the task. |
---|
| 25 | * Requested calculation should be done based on the resources allocated for the task, |
---|
| 26 | * task description and task completion percentage. |
---|
| 27 | * |
---|
| 28 | * Example implementation calculate the estimation based on cpu processing power. |
---|
| 29 | * There is also a simple assumption, that cpu processing power is a linear function |
---|
| 30 | * of number of allocated cpus and their speed. |
---|
| 31 | */ |
---|
| 32 | public double execTimeEstimation(SchedulingEvent event, ExecTask task, |
---|
| 33 | Map<ResourceUnitName, ResourceUnit> allocatedResources, |
---|
| 34 | double completionPercentage) { |
---|
| 35 | |
---|
| 36 | // collect all information necessary to do the calculation |
---|
| 37 | PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE); |
---|
| 38 | |
---|
| 39 | // obtain single pe speed |
---|
| 40 | int speed = peUnit.getSpeed(); |
---|
| 41 | |
---|
| 42 | // number of used pe |
---|
| 43 | int cnt = peUnit.getUsedAmount(); |
---|
| 44 | |
---|
| 45 | // estimate remainingTaskLength |
---|
[497] | 46 | double remainingLength = task.getLength() * (1 - completionPercentage/100); |
---|
[477] | 47 | |
---|
| 48 | // do the calculation |
---|
| 49 | double execTime = (remainingLength / (cnt * speed)); |
---|
| 50 | |
---|
| 51 | // if the result is very close to 0, but less then one millisecond then round this result to 0.001 |
---|
| 52 | if (Double.compare(execTime, 0.001) < 0) { |
---|
| 53 | execTime = 0.001; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | // time is measured in integer units, so get the nearest execTime int value. |
---|
| 57 | execTime = Math.ceil(execTime); |
---|
| 58 | return execTime; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | } |
---|