summaryrefslogtreecommitdiff
path: root/opendc-compute/opendc-compute-simulator
diff options
context:
space:
mode:
authorDante Niewenhuis <d.niewenhuis@hotmail.com>2025-02-03 13:11:48 +0100
committerGitHub <noreply@github.com>2025-02-03 13:11:48 +0100
commitdf1028c71cb6d50db886c8076c7139ec24feb6d7 (patch)
tree9ab240a87df720d5eec588027c84a4d614bb4394 /opendc-compute/opendc-compute-simulator
parentf471d06e842f3675b634c4ceceb108cfd8817837 (diff)
Added Batteries (#300)
* Batteries are implemented. Small problem with the deletion when running larger workloads. Added mock files for the Battery implementation. Updated the Carbon Model to allow for multiple receivers of CarbonIntensity * Implemented batteries in OpenDC. * Spotless applied
Diffstat (limited to 'opendc-compute/opendc-compute-simulator')
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt1
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/HostsProvisioningStep.kt52
2 files changed, 46 insertions, 7 deletions
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt
index 7f5f09eb..83968d35 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt
@@ -96,6 +96,7 @@ public class Guest(
val scalingPolicy = NoDelayScaling()
+ // TODO: This is not being used at the moment
val bootworkload =
TraceWorkload(
ArrayList(
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 933b4e63..572335e1 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,7 +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.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
@@ -57,15 +61,50 @@ public class HostsProvisioningStep internal constructor(
for (cluster in clusterSpecs) {
// Create the Power Source to which hosts are connected
+ // Create Power Source
+ val simPowerSource = SimPowerSource(graph, cluster.powerSource.totalPower.toDouble())
+ simPowerSources.add(simPowerSource)
+ service.addPowerSource(simPowerSource)
+
+ val hostDistributor = FlowDistributor(graph)
+
val carbonFragments = getCarbonFragments(cluster.powerSource.carbonTracePath)
- val simPowerSource = SimPowerSource(graph, cluster.powerSource.totalPower.toDouble(), carbonFragments, startTime)
+ var carbonModel: CarbonModel? = null
+ // Create Carbon Model
+ if (carbonFragments != null) {
+ carbonModel = CarbonModel(graph, carbonFragments, startTime)
+ carbonModel.addReceiver(simPowerSource)
+ }
- service.addPowerSource(simPowerSource)
- simPowerSources.add(simPowerSource)
+ if (cluster.battery != null) {
+ // Create Battery Distributor
+ val batteryDistributor = FlowDistributor(graph)
+ graph.addEdge(batteryDistributor, simPowerSource)
- val powerDistributor = FlowDistributor(graph)
- graph.addEdge(powerDistributor, simPowerSource)
+ // Create Battery
+ val battery =
+ SimBattery(graph, cluster.battery!!.capacity, cluster.battery!!.chargingSpeed, cluster.battery!!.initialCharge)
+ graph.addEdge(battery, batteryDistributor)
+
+ // Create Aggregator
+ val batteryAggregator = BatteryAggregator(graph, battery, batteryDistributor)
+
+ // Create BatteryPolicy
+ val batteryPolicy =
+ SingleThresholdBatteryPolicy(
+ graph,
+ battery,
+ batteryAggregator,
+ cluster.battery!!.batteryPolicy.carbonThreshold,
+ )
+
+ carbonModel?.addReceiver(batteryPolicy)
+
+ graph.addEdge(hostDistributor, batteryAggregator)
+ } else {
+ graph.addEdge(hostDistributor, simPowerSource)
+ }
// Create hosts, they are connected to the powerMux when SimMachine is created
for (hostSpec in cluster.hostSpecs) {
@@ -78,7 +117,7 @@ public class HostsProvisioningStep internal constructor(
graph,
hostSpec.model,
hostSpec.cpuPowerModel,
- powerDistributor,
+ hostDistributor,
)
require(simHosts.add(simHost)) { "Host with uid ${hostSpec.uid} already exists" }
@@ -92,7 +131,6 @@ public class HostsProvisioningStep internal constructor(
}
for (simPowerSource in simPowerSources) {
- // TODO: add close function
simPowerSource.close()
}
}