summaryrefslogtreecommitdiff
path: root/opendc-compute
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-compute')
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/ComputeSchedulers.kt6
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/MemorizingScheduler.kt28
2 files changed, 22 insertions, 12 deletions
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/ComputeSchedulers.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/ComputeSchedulers.kt
index 7f4f2f07..8f2369dc 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/ComputeSchedulers.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/ComputeSchedulers.kt
@@ -44,6 +44,7 @@ public enum class ComputeSchedulerEnum {
ProvisionedCores,
ProvisionedCoresInv,
Random,
+ TaskNumMemorizing,
}
public fun createComputeScheduler(
@@ -110,5 +111,10 @@ public fun createComputeScheduler(
subsetSize = Int.MAX_VALUE,
random = SplittableRandom(seeder.nextLong()),
)
+ ComputeSchedulerEnum.TaskNumMemorizing ->
+ MemorizingScheduler(
+ filters = listOf(ComputeFilter(), VCpuFilter(cpuAllocationRatio), RamFilter(ramAllocationRatio)),
+ random = SplittableRandom(seeder.nextLong()),
+ )
}
}
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/MemorizingScheduler.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/MemorizingScheduler.kt
index d3b590f7..c48e6fb0 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/MemorizingScheduler.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/MemorizingScheduler.kt
@@ -58,7 +58,7 @@ public class MemorizingScheduler(
val listIdx = host.listIndex
val chosenList = hostsQueue[priorityIdx]
- if (listIdx == chosenList.size - 1) {
+ if (chosenList.size == 1) {
chosenList.removeLast()
if (listIdx == minAvailableHost) {
for (i in minAvailableHost + 1..hostsQueue.lastIndex) {
@@ -111,18 +111,20 @@ public class MemorizingScheduler(
if (result == null) return SchedulingResult(SchedulingResultType.EMPTY) // No tasks to schedule that fit
// Bookkeeping to maintain the calendar priority queue
- val listIdx = chosenHost!!.listIndex
-
- if (listIdx == chosenList!!.size - 1) {
+ if (chosenList!!.size == 1) {
chosenList.removeLast()
- if (chosenList.isEmpty()) minAvailableHost++
+ minAvailableHost++
} else {
- val lastItem = chosenList.removeLast()
+ val listIdx = chosenHost!!.listIndex
+ // Not using removeLast here as it would cause problems during swapping
+ // if chosenHost is lastItem
+ val lastItem = chosenList.last()
chosenList[listIdx] = lastItem
lastItem.listIndex = listIdx
+ chosenList.removeLast()
}
- val nextList = hostsQueue[chosenHost.priorityIndex + 1]
+ val nextList = hostsQueue[chosenHost!!.priorityIndex + 1]
nextList.add(chosenHost)
chosenHost.priorityIndex++
chosenHost.listIndex = nextList.size - 1
@@ -141,18 +143,20 @@ public class MemorizingScheduler(
val chosenList = hostsQueue[priorityIdx]
val nextList = hostsQueue[priorityIdx - 1]
- if (listIdx == chosenList.size - 1) {
+ if (chosenList.size == 1) {
chosenList.removeLast()
- if (priorityIdx == minAvailableHost) {
- minAvailableHost--
- }
} else {
- val lastItem = chosenList.removeLast()
+ val lastItem = chosenList.last()
chosenList[listIdx] = lastItem
lastItem.listIndex = listIdx
+ chosenList.removeLast()
}
+
nextList.add(host)
host.priorityIndex--
host.listIndex = nextList.size - 1
+ if (priorityIdx == minAvailableHost) {
+ minAvailableHost--
+ }
}
}