summaryrefslogtreecommitdiff
path: root/opendc-compute/opendc-compute-simulator/src/main/java
diff options
context:
space:
mode:
authorDante Niewenhuis <d.niewenhuis@hotmail.com>2025-03-24 14:07:01 +0100
committerGitHub <noreply@github.com>2025-03-24 14:07:01 +0100
commitea45406229c8349e44c88f4112fe25435b59e4e9 (patch)
treeba701816711f7a5e30cef8d1d5ad990248d43a05 /opendc-compute/opendc-compute-simulator/src/main/java
parent24f89ae21df182bb91d92e4a60b4049829ac4d9e (diff)
Added embodied carbon to hosts (#326)
Diffstat (limited to 'opendc-compute/opendc-compute-simulator/src/main/java')
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ComputeService.java49
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ServiceTask.java2
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/telemetry/HostSystemStats.java1
3 files changed, 36 insertions, 16 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 657e7f1e..b4b34881 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
@@ -23,7 +23,6 @@
package org.opendc.compute.simulator.service;
import java.time.Duration;
-import java.time.Instant;
import java.time.InstantSource;
import java.time.temporal.TemporalAmount;
import java.util.ArrayDeque;
@@ -128,6 +127,7 @@ public final class ComputeService implements AutoCloseable, CarbonReceiver {
/**
* The active tasks in the system.
+ * TODO: this is not doing anything, maybe delete it?
*/
private final Map<ServiceTask, SimHost> completedTasks = new HashMap<>();
@@ -408,13 +408,30 @@ public final class ComputeService implements AutoCloseable, CarbonReceiver {
* Enqueue the specified [task] to be scheduled onto a host.
*/
SchedulingRequest schedule(ServiceTask task) {
+ return schedule(task, false);
+ }
+
+ SchedulingRequest schedule(ServiceTask task, boolean atFront) {
LOGGER.debug("Enqueueing task {} to be assigned to host", task.getUid());
+ if (task.getNumFailures() >= maxNumFailures) {
+ LOGGER.warn("task {} has been terminated because it failed {} times", task, task.getNumFailures());
+
+ tasksTerminated++;
+ task.setState(TaskState.TERMINATED);
+
+ this.setTaskToBeRemoved(task);
+ return null;
+ }
+
long now = clock.millis();
SchedulingRequest request = new SchedulingRequest(task, now);
- task.scheduledAt = Instant.ofEpochMilli(now);
- taskQueue.add(request);
+ if (atFront) {
+ taskQueue.addFirst(request);
+ } else {
+ taskQueue.add(request);
+ }
tasksPending++;
requestSchedulingCycle();
return request;
@@ -473,18 +490,19 @@ public final class ComputeService implements AutoCloseable, CarbonReceiver {
final ServiceFlavor flavor = task.getFlavor();
- if (task.getNumFailures() >= maxNumFailures) {
- LOGGER.warn("task {} has been terminated because it failed {} times", task, task.getNumFailures());
-
- taskQueue.remove(req);
- tasksPending--;
- tasksTerminated++;
- task.setState(TaskState.TERMINATED);
-
- scheduler.removeTask(task, hv);
- this.setTaskToBeRemoved(task);
- continue;
- }
+ // if (task.getNumFailures() >= maxNumFailures) {
+ // LOGGER.warn("task {} has been terminated because it failed {} times", task,
+ // task.getNumFailures());
+ //
+ // taskQueue.remove(req);
+ // tasksPending--;
+ // tasksTerminated++;
+ // task.setState(TaskState.TERMINATED);
+ //
+ // scheduler.removeTask(task, hv);
+ // this.setTaskToBeRemoved(task);
+ // continue;
+ // }
if (result.getResultType() == SchedulingResultType.FAILURE) {
LOGGER.trace("Task {} selected for scheduling but no capacity available for it at the moment", task);
@@ -516,6 +534,7 @@ public final class ComputeService implements AutoCloseable, CarbonReceiver {
try {
task.host = host;
+ task.scheduledAt = clock.instant();
host.spawn(task);
diff --git a/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ServiceTask.java b/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ServiceTask.java
index 9fb9b5f0..cada796a 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ServiceTask.java
+++ b/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ServiceTask.java
@@ -185,7 +185,7 @@ public class ServiceTask {
case FAILED:
LOGGER.info("User requested to start task after failure {}", uid);
setState(TaskState.PROVISIONING);
- request = service.schedule(this);
+ request = service.schedule(this, true);
break;
}
}
diff --git a/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/telemetry/HostSystemStats.java b/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/telemetry/HostSystemStats.java
index aa292797..8a7d022e 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/telemetry/HostSystemStats.java
+++ b/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/telemetry/HostSystemStats.java
@@ -44,6 +44,7 @@ public record HostSystemStats(
Instant bootTime,
double powerDraw,
double energyUsage,
+ double embodiedCarbon,
int guestsTerminated,
int guestsRunning,
int guestsError,