From fb7d3010d6141dd518d8ebfacd41d399c3f9758d Mon Sep 17 00:00:00 2001 From: Sacheendra Talluri Date: Sat, 22 Mar 2025 11:04:32 +0100 Subject: Shift task execution to the valley of carbon emissions (#323) * Move shifted task execution to the valley of carbon emissions * Remove error from compute service * spotless apply * Run scheduling cycle everytime carbon intensity updates --- .../opendc/compute/simulator/service/ComputeService.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'opendc-compute/opendc-compute-simulator/src/main/java/org') diff --git a/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ComputeService.java b/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ComputeService.java index 69625306..0538a951 100644 --- a/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ComputeService.java +++ b/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ComputeService.java @@ -55,6 +55,8 @@ import org.opendc.compute.simulator.scheduler.SchedulingResult; import org.opendc.compute.simulator.scheduler.SchedulingResultType; import org.opendc.compute.simulator.telemetry.ComputeMetricReader; import org.opendc.compute.simulator.telemetry.SchedulerStats; +import org.opendc.simulator.compute.power.CarbonModel; +import org.opendc.simulator.compute.power.CarbonReceiver; import org.opendc.simulator.compute.power.SimPowerSource; import org.opendc.simulator.compute.power.batteries.SimBattery; import org.opendc.simulator.compute.workload.Workload; @@ -64,7 +66,7 @@ import org.slf4j.LoggerFactory; /** * The {@link ComputeService} hosts the API implementation of the OpenDC Compute Engine. */ -public final class ComputeService implements AutoCloseable { +public final class ComputeService implements AutoCloseable, CarbonReceiver { private static final Logger LOGGER = LoggerFactory.getLogger(ComputeService.class); /** @@ -433,6 +435,14 @@ public final class ComputeService implements AutoCloseable { taskById.remove(task.getUid()); } + public void updateCarbonIntensity(double newCarbonIntensity) { + requestSchedulingCycle(); + } + + public void setCarbonModel(CarbonModel carbonModel) {} + + public void removeCarbonModel(CarbonModel carbonModel) {} + /** * Indicate that a new scheduling cycle is needed due to a change to the service's state. */ @@ -449,12 +459,12 @@ public final class ComputeService implements AutoCloseable { * Run a single scheduling iteration. */ private void doSchedule() { - for (Iterator iterator = taskQueue.iterator(); iterator.hasNext(); iterator = taskQueue.iterator()) { final SchedulingResult result = scheduler.select(iterator); if (result.getResultType() == SchedulingResultType.EMPTY) { + break; } final HostView hv = result.getHost(); -- cgit v1.2.3