summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDante Niewenhuis <d.niewenhuis@hotmail.com>2025-03-29 13:59:35 +0100
committerGitHub <noreply@github.com>2025-03-29 13:59:35 +0100
commitaf632099d05636af3274ee95ada6b962703a67f0 (patch)
treeeea693722038de825a3728c65751d20115766feb
parentb20dd5ebb48465470b9632dc92ecfb1794a8a4bf (diff)
Fixed a small problem with getForeCast (#328)
* Fixed a small problem with carbon forecasts that would cause problems when the simulation would leave the coverage of the carbon Trace * Fixed a small problem with carbon forecasts that would cause problems when the simulation would leave the coverage of the carbon Trace * Fixed a bug * spotless applied
-rw-r--r--opendc-compute/opendc-compute-failure/src/main/kotlin/org/opendc/compute/failure/victimselector/StochasticVictimSelector.kt3
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/MemorizingScheduler.kt2
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/timeshift/TaskStopper.kt4
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/timeshift/TimeshiftScheduler.kt7
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonModel.java6
5 files changed, 15 insertions, 7 deletions
diff --git a/opendc-compute/opendc-compute-failure/src/main/kotlin/org/opendc/compute/failure/victimselector/StochasticVictimSelector.kt b/opendc-compute/opendc-compute-failure/src/main/kotlin/org/opendc/compute/failure/victimselector/StochasticVictimSelector.kt
index 9b92cf33..1c7d1e7d 100644
--- a/opendc-compute/opendc-compute-failure/src/main/kotlin/org/opendc/compute/failure/victimselector/StochasticVictimSelector.kt
+++ b/opendc-compute/opendc-compute-failure/src/main/kotlin/org/opendc/compute/failure/victimselector/StochasticVictimSelector.kt
@@ -27,6 +27,7 @@ import java.util.SplittableRandom
import java.util.random.RandomGenerator
import kotlin.math.max
import kotlin.math.min
+import kotlin.math.roundToInt
/**
* A [VictimSelector] that stochastically selects a set of hosts to be failed.
@@ -73,7 +74,7 @@ public class StochasticVictimSelector(
): List<SimHost> {
// clamp value between 0.0 and 1.0
val intensity = min(1.0, max(0.0, failureIntensity))
- val numberOfHosts = (hosts.size * intensity).toInt()
+ val numberOfHosts = (hosts.size * intensity).roundToInt()
return hosts.asSequence().shuffled().take(numberOfHosts).toList()
}
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 4a561e95..25e559fd 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
@@ -40,7 +40,7 @@ public class MemorizingScheduler(
) : ComputeScheduler {
// We assume that there will be max 200 tasks per host.
// The index of a host list is the number of tasks on that host.
- private val hostsQueue = List(20000, { mutableListOf<HostView>() })
+ private val hostsQueue = List(100, { mutableListOf<HostView>() })
private var minAvailableHost = 0
private var numHosts = 0
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/timeshift/TaskStopper.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/timeshift/TaskStopper.kt
index 4ea526b7..7549bb1c 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/timeshift/TaskStopper.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/timeshift/TaskStopper.kt
@@ -79,7 +79,9 @@ public class TaskStopper(
isHighCarbon = noForecastUpdateCarbonIntensity(newCarbonIntensity)
} else {
val forecast = carbonModel!!.getForecast(forecastSize)
- val quantileIndex = (forecastSize * forecastThreshold).roundToInt()
+
+ val localForecastSize = forecast.size
+ val quantileIndex = (localForecastSize * forecastThreshold).roundToInt()
val thresholdCarbonIntensity = forecast.sorted()[quantileIndex]
isHighCarbon = newCarbonIntensity > thresholdCarbonIntensity
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/timeshift/TimeshiftScheduler.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/timeshift/TimeshiftScheduler.kt
index 2f9b4364..f402c5a5 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/timeshift/TimeshiftScheduler.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/timeshift/TimeshiftScheduler.kt
@@ -171,10 +171,11 @@ public class TimeshiftScheduler(
}
val forecast = carbonModel!!.getForecast(forecastSize)
- val forecastSize = forecast.size
- val shortQuantileIndex = (forecastSize * shortForecastThreshold).roundToInt()
+ val localForecastSize = forecast.size
+
+ val shortQuantileIndex = (localForecastSize * shortForecastThreshold).roundToInt()
val shortCarbonIntensity = forecast.sorted()[shortQuantileIndex]
- val longQuantileIndex = (forecastSize * longForecastThreshold).roundToInt()
+ val longQuantileIndex = (localForecastSize * longForecastThreshold).roundToInt()
val longCarbonIntensity = forecast.sorted()[longQuantileIndex]
shortLowCarbon = newCarbonIntensity < shortCarbonIntensity
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonModel.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonModel.java
index 3cf36ece..e1c99071 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonModel.java
+++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonModel.java
@@ -134,7 +134,11 @@ public class CarbonModel extends FlowNode {
}
public double[] getForecast(int forecastSize) {
- return this.fragments.subList(this.fragment_index + 1, this.fragment_index + forecastSize).stream()
+ return this.fragments
+ .subList(
+ Math.min(this.fragment_index + 1, this.fragments.size() - 1),
+ Math.min(this.fragment_index + forecastSize, this.fragments.size()))
+ .stream()
.mapToDouble(CarbonFragment::getCarbonIntensity)
.toArray();
}