summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSacheendra Talluri <sacheendra.t@gmail.com>2025-03-18 09:56:36 +0100
committerGitHub <noreply@github.com>2025-03-18 09:56:36 +0100
commit582c45b6457bc9dc6fed57a843c87097db991d4a (patch)
tree64885718fa9f235a7c2ba5edb06c35d995925098
parent97db8e0351b9451ece8fd16c25ca0588ec71a2ab (diff)
Fixed memorizing scheduler with correct last elem check (#317)
* Fixed memorizing scheduler with correct last elem check * Fix spotless complaints
-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--
+ }
}
}