[1393] | 1 | package test.cpusharing; |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | import java.util.Map; |
---|
| 5 | |
---|
| 6 | import dcworms.schedframe.scheduling.ExecTask; |
---|
| 7 | import example.timeestimation.BaseTimeEstimationPlugin; |
---|
| 8 | |
---|
| 9 | import schedframe.events.scheduling.SchedulingEvent; |
---|
| 10 | import schedframe.resources.units.PEUnit; |
---|
| 11 | import schedframe.resources.units.ProcessingElements; |
---|
| 12 | import schedframe.resources.units.ResourceUnit; |
---|
| 13 | import schedframe.resources.units.ResourceUnitName; |
---|
| 14 | import schedframe.resources.units.StandardResourceUnitName; |
---|
| 15 | import schedframe.scheduling.manager.tasks.JobRegistryImpl; |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | /** |
---|
| 19 | * |
---|
| 20 | * @author Marcin Krystek && Wojciech Piatek |
---|
| 21 | * |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | public 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 | } |
---|