summaryrefslogtreecommitdiff
path: root/opendc-compute/opendc-compute-simulator/src/main/java/org
diff options
context:
space:
mode:
authorSacheendra Talluri <sacheendra.t@gmail.com>2025-03-22 11:04:32 +0100
committerGitHub <noreply@github.com>2025-03-22 11:04:32 +0100
commitfb7d3010d6141dd518d8ebfacd41d399c3f9758d (patch)
tree477015155dd251bb4a3fbde0c0192d35336effe8 /opendc-compute/opendc-compute-simulator/src/main/java/org
parent702b739a53115f14c402dc24ec30468ef47db2d8 (diff)
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
Diffstat (limited to 'opendc-compute/opendc-compute-simulator/src/main/java/org')
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ComputeService.java14
1 files changed, 12 insertions, 2 deletions
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<SchedulingRequest> 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();