From af632099d05636af3274ee95ada6b962703a67f0 Mon Sep 17 00:00:00 2001 From: Dante Niewenhuis Date: Sat, 29 Mar 2025 13:59:35 +0100 Subject: 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 --- .../org/opendc/compute/simulator/scheduler/MemorizingScheduler.kt | 2 +- .../opendc/compute/simulator/scheduler/timeshift/TaskStopper.kt | 4 +++- .../compute/simulator/scheduler/timeshift/TimeshiftScheduler.kt | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) (limited to 'opendc-compute/opendc-compute-simulator') 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() }) + private val hostsQueue = List(100, { mutableListOf() }) 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 -- cgit v1.2.3