From 7dc2639a7fcdf51ef789f4af2e3afff11438be6e Mon Sep 17 00:00:00 2001 From: Dante Niewenhuis Date: Fri, 14 Mar 2025 15:33:42 +0100 Subject: Added more battery policies (#312) * some updates * Updates * Added comments and renamed variables * Ran Spotless --- .../opendc/compute/simulator/service/ComputeService.java | 16 ++-------------- .../simulator/provisioner/HostsProvisioningStep.kt | 7 +++---- .../compute/simulator/telemetry/ComputeMetricReader.kt | 4 ++-- 3 files changed, 7 insertions(+), 20 deletions(-) (limited to 'opendc-compute/opendc-compute-simulator/src/main') 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 aa2c13b9..1fb9c6a2 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 @@ -148,8 +148,6 @@ public final class ComputeService implements AutoCloseable { */ private final Map taskById = new HashMap<>(); - private final List tasks = new ArrayList<>(); - private final List tasksToRemove = new ArrayList<>(); private ComputeMetricReader metricReader; @@ -265,8 +263,8 @@ public final class ComputeService implements AutoCloseable { /** * Return the {@link ServiceTask}s hosted by this service. */ - public List getTasks() { - return Collections.unmodifiableList(tasks); + public Map getTasks() { + return taskById; } /** @@ -433,7 +431,6 @@ public final class ComputeService implements AutoCloseable { void delete(ServiceTask task) { completedTasks.remove(task); taskById.remove(task.getUid()); - tasks.remove(task); } /** @@ -452,7 +449,6 @@ public final class ComputeService implements AutoCloseable { * Run a single scheduling iteration. */ private void doSchedule() { - // reorder tasks for (Iterator iterator = taskQueue.iterator(); iterator.hasNext(); @@ -660,7 +656,6 @@ public final class ComputeService implements AutoCloseable { ServiceTask task = new ServiceTask(service, uid, name, internalFlavor, workload, meta); service.taskById.put(uid, task); - service.tasks.add(task); service.tasksTotal++; @@ -675,13 +670,6 @@ public final class ComputeService implements AutoCloseable { return service.taskById.get(id); } - @NotNull - public List queryTasks() { - checkOpen(); - - return new ArrayList<>(service.tasks); - } - public void close() { isClosed = true; } diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/HostsProvisioningStep.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/HostsProvisioningStep.kt index 68395fe4..211f33fe 100644 --- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/HostsProvisioningStep.kt +++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/HostsProvisioningStep.kt @@ -27,11 +27,11 @@ import org.opendc.compute.simulator.host.SimHost import org.opendc.compute.simulator.service.ComputeService import org.opendc.compute.topology.specs.ClusterSpec import org.opendc.compute.topology.specs.HostSpec +import org.opendc.compute.topology.specs.createSimBatteryPolicy import org.opendc.simulator.compute.power.CarbonModel import org.opendc.simulator.compute.power.SimPowerSource import org.opendc.simulator.compute.power.batteries.BatteryAggregator import org.opendc.simulator.compute.power.batteries.SimBattery -import org.opendc.simulator.compute.power.batteries.policy.SingleThresholdBatteryPolicy import org.opendc.simulator.engine.engine.FlowEngine import org.opendc.simulator.engine.graph.FlowDistributor @@ -99,13 +99,12 @@ public class HostsProvisioningStep internal constructor( // Create Aggregator val batteryAggregator = BatteryAggregator(graph, battery, batteryDistributor) - // Create BatteryPolicy val batteryPolicy = - SingleThresholdBatteryPolicy( + createSimBatteryPolicy( + cluster.battery!!.batteryPolicy, graph, battery, batteryAggregator, - cluster.battery!!.batteryPolicy.carbonThreshold, ) carbonModel?.addReceiver(batteryPolicy) diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/ComputeMetricReader.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/ComputeMetricReader.kt index 91748454..c88b98ea 100644 --- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/ComputeMetricReader.kt +++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/ComputeMetricReader.kt @@ -140,7 +140,7 @@ public class ComputeMetricReader( } if (toMonitor[OutputFiles.TASK] == true) { - for (task in this.service.tasks) { + for (task in this.service.tasks.values) { val reader = this.taskTableReaders.computeIfAbsent(task) { TaskTableReaderImpl( @@ -197,7 +197,7 @@ public class ComputeMetricReader( monitor.record(this.serviceTableReader.copy()) } - if (loggCounter >= 100) { + if (loggCounter >= 24) { var loggString = "\n\t\t\t\t\tMetrics after ${now.toEpochMilli() / 1000 / 60 / 60} hours:\n" loggString += "\t\t\t\t\t\tTasks Total: ${this.serviceTableReader.tasksTotal}\n" loggString += "\t\t\t\t\t\tTasks Active: ${this.serviceTableReader.tasksActive}\n" -- cgit v1.2.3