summaryrefslogtreecommitdiff
path: root/opendc-compute/opendc-compute-simulator
diff options
context:
space:
mode:
authorDante Niewenhuis <d.niewenhuis@hotmail.com>2024-11-03 20:00:26 +0100
committerGitHub <noreply@github.com>2024-11-03 20:00:26 +0100
commitf3e578a2a43c99997dbf35e09debfde255a4ae22 (patch)
tree312dde871072cff0468d2a5a11cd671d85063220 /opendc-compute/opendc-compute-simulator
parent6fa203b9187b474816e7719baed8c97eadd689cb (diff)
Rewritten the Carbon model (#260)
Diffstat (limited to 'opendc-compute/opendc-compute-simulator')
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ComputeService.java7
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeMonitorProvisioningStep.kt3
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeSteps.kt7
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/HostsProvisioningStep.kt11
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/ComputeMetricReader.kt4
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/parquet/DfltHostExportColumns.kt10
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReader.kt10
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReaderImpl.kt17
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/PowerSourceTableReaderImpl.kt12
9 files changed, 23 insertions, 58 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 8df0d7d8..b6a69209 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
@@ -346,8 +346,11 @@ public final class ComputeService implements AutoCloseable {
public void setTaskToBeRemoved(ServiceTask task) {
this.tasksToRemove.add(task);
- if ((tasksTerminated + tasksCompleted) == tasksExpected) {
- metricReader.loggState(); // Logg the state for the final time. This will also delete all remaining tasks.
+ if ((this.tasksTerminated + this.tasksCompleted) == this.tasksExpected) {
+ if (this.metricReader != null) {
+ this.metricReader
+ .loggState(); // Logg the state for the final time. This will also delete all remaining tasks.
+ }
}
}
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeMonitorProvisioningStep.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeMonitorProvisioningStep.kt
index da6dcfbc..29e9d541 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeMonitorProvisioningStep.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeMonitorProvisioningStep.kt
@@ -22,7 +22,6 @@
package org.opendc.compute.simulator.provisioner
-import org.opendc.compute.carbon.CarbonTrace
import org.opendc.compute.simulator.service.ComputeService
import org.opendc.compute.simulator.telemetry.ComputeMetricReader
import org.opendc.compute.simulator.telemetry.ComputeMonitor
@@ -37,7 +36,6 @@ public class ComputeMonitorProvisioningStep(
private val monitor: ComputeMonitor,
private val exportInterval: Duration,
private val startTime: Duration = Duration.ofMillis(0),
- private val carbonTrace: CarbonTrace = CarbonTrace(null),
) : ProvisioningStep {
override fun apply(ctx: ProvisioningContext): AutoCloseable {
val service =
@@ -51,7 +49,6 @@ public class ComputeMonitorProvisioningStep(
monitor,
exportInterval,
startTime,
- carbonTrace,
)
return metricReader
}
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeSteps.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeSteps.kt
index d8bb703e..7d9cae60 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeSteps.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeSteps.kt
@@ -24,7 +24,6 @@
package org.opendc.compute.simulator.provisioner
-import org.opendc.compute.carbon.CarbonTrace
import org.opendc.compute.simulator.scheduler.ComputeScheduler
import org.opendc.compute.simulator.telemetry.ComputeMonitor
import org.opendc.compute.topology.specs.ClusterSpec
@@ -60,9 +59,8 @@ public fun registerComputeMonitor(
monitor: ComputeMonitor,
exportInterval: Duration = Duration.ofMinutes(5),
startTime: Duration = Duration.ofMillis(0),
- carbonTrace: CarbonTrace = CarbonTrace(null),
): ProvisioningStep {
- return ComputeMonitorProvisioningStep(serviceDomain, monitor, exportInterval, startTime, carbonTrace)
+ return ComputeMonitorProvisioningStep(serviceDomain, monitor, exportInterval, startTime)
}
/**
@@ -76,6 +74,7 @@ public fun registerComputeMonitor(
public fun setupHosts(
serviceDomain: String,
specs: List<ClusterSpec>,
+ startTime: Long = 0L,
): ProvisioningStep {
- return HostsProvisioningStep(serviceDomain, specs)
+ return HostsProvisioningStep(serviceDomain, specs, startTime)
}
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 d2231f0d..8e7293c8 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
@@ -22,6 +22,7 @@
package org.opendc.compute.simulator.provisioner
+import org.opendc.compute.carbon.getCarbonFragments
import org.opendc.compute.simulator.host.SimHost
import org.opendc.compute.simulator.service.ComputeService
import org.opendc.compute.topology.specs.ClusterSpec
@@ -40,6 +41,7 @@ import org.opendc.simulator.engine.FlowEngine
public class HostsProvisioningStep internal constructor(
private val serviceDomain: String,
private val clusterSpecs: List<ClusterSpec>,
+ private val startTime: Long = 0L,
) : ProvisioningStep {
override fun apply(ctx: ProvisioningContext): AutoCloseable {
val service =
@@ -54,8 +56,11 @@ public class HostsProvisioningStep internal constructor(
for (cluster in clusterSpecs) {
// Create the Power Source to which hosts are connected
- // TODO: Add connection to totalPower
- val simPowerSource = SimPowerSource(graph)
+
+ val carbonFragments = getCarbonFragments(cluster.powerSource.carbonTracePath)
+
+ val simPowerSource = SimPowerSource(graph, cluster.powerSource.totalPower.toDouble(), carbonFragments, startTime)
+
service.addPowerSource(simPowerSource)
simPowerSources.add(simPowerSource)
@@ -88,7 +93,7 @@ public class HostsProvisioningStep internal constructor(
for (simPowerSource in simPowerSources) {
// TODO: add close function
-// simPowerSource.close()
+ simPowerSource.close()
}
}
}
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 3098ed55..5dab5d7a 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
@@ -29,7 +29,6 @@ import kotlinx.coroutines.launch
import mu.KotlinLogging
import org.opendc.common.Dispatcher
import org.opendc.common.asCoroutineDispatcher
-import org.opendc.compute.carbon.CarbonTrace
import org.opendc.compute.simulator.host.SimHost
import org.opendc.compute.simulator.service.ComputeService
import org.opendc.compute.simulator.service.ServiceTask
@@ -55,7 +54,6 @@ public class ComputeMetricReader(
private val monitor: ComputeMonitor,
private val exportInterval: Duration = Duration.ofMinutes(5),
private val startTime: Duration = Duration.ofMillis(0),
- private val carbonTrace: CarbonTrace = CarbonTrace(null),
) : AutoCloseable {
private val logger = KotlinLogging.logger {}
private val scope = CoroutineScope(dispatcher.asCoroutineDispatcher())
@@ -119,7 +117,6 @@ public class ComputeMetricReader(
HostTableReaderImpl(
it,
startTime,
- carbonTrace,
)
}
reader.record(now)
@@ -152,7 +149,6 @@ public class ComputeMetricReader(
PowerSourceTableReaderImpl(
it,
startTime,
- carbonTrace,
)
}
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/parquet/DfltHostExportColumns.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/parquet/DfltHostExportColumns.kt
index 1b76da6b..805b224d 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/parquet/DfltHostExportColumns.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/parquet/DfltHostExportColumns.kt
@@ -154,16 +154,6 @@ public object DfltHostExportColumns {
field = Types.required(FLOAT).named("energy_usage"),
) { it.energyUsage }
- public val CARBON_INTENSITY: ExportColumn<HostTableReader> =
- ExportColumn(
- field = Types.required(FLOAT).named("carbon_intensity"),
- ) { it.carbonIntensity }
-
- public val CARBON_EMISSION: ExportColumn<HostTableReader> =
- ExportColumn(
- field = Types.required(FLOAT).named("carbon_emission"),
- ) { it.carbonEmission }
-
public val UP_TIME: ExportColumn<HostTableReader> =
ExportColumn(
field = Types.required(INT64).named("uptime"),
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReader.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReader.kt
index cf8d3c8c..35565f82 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReader.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReader.kt
@@ -123,16 +123,6 @@ public interface HostTableReader : Exportable {
public val energyUsage: Double
/**
- * The current carbon intensity of the host in gCO2 / kW.
- */
- public val carbonIntensity: Double
-
- /**
- * The current carbon emission since the last deadline in g.
- */
- public val carbonEmission: Double
-
- /**
* The uptime of the host since last time in ms.
*/
public val uptime: Long
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReaderImpl.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReaderImpl.kt
index ab8c0036..90f091f2 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReaderImpl.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReaderImpl.kt
@@ -22,7 +22,6 @@
package org.opendc.compute.simulator.telemetry.table
-import org.opendc.compute.carbon.CarbonTrace
import org.opendc.compute.simulator.host.SimHost
import java.time.Duration
import java.time.Instant
@@ -33,7 +32,6 @@ import java.time.Instant
public class HostTableReaderImpl(
host: SimHost,
private val startTime: Duration = Duration.ofMillis(0),
- private val carbonTrace: CarbonTrace = CarbonTrace(null),
) : HostTableReader {
override fun copy(): HostTableReader {
val newHostTable =
@@ -61,8 +59,6 @@ public class HostTableReaderImpl(
_cpuLostTime = table.cpuLostTime
_powerDraw = table.powerDraw
_energyUsage = table.energyUsage
- _carbonIntensity = table.carbonIntensity
- _carbonEmission = table.carbonEmission
_uptime = table.uptime
_downtime = table.downtime
_bootTime = table.bootTime
@@ -150,14 +146,6 @@ public class HostTableReaderImpl(
private var _energyUsage = 0.0
private var previousEnergyUsage = 0.0
- override val carbonIntensity: Double
- get() = _carbonIntensity
- private var _carbonIntensity = 0.0
-
- override val carbonEmission: Double
- get() = _carbonEmission
- private var _carbonEmission = 0.0
-
override val uptime: Long
get() = _uptime - previousUptime
private var _uptime = 0L
@@ -200,9 +188,6 @@ public class HostTableReaderImpl(
_cpuLostTime = hostCpuStats.lostTime
_powerDraw = hostSysStats.powerDraw
_energyUsage = hostSysStats.energyUsage
- _carbonIntensity = carbonTrace.getCarbonIntensity(timestampAbsolute)
-
- _carbonEmission = carbonIntensity * (energyUsage / 3600000.0) // convert energy usage from J to kWh
_uptime = hostSysStats.uptime.toMillis()
_downtime = hostSysStats.downtime.toMillis()
_bootTime = hostSysStats.bootTime
@@ -234,7 +219,5 @@ public class HostTableReaderImpl(
_powerDraw = 0.0
_energyUsage = 0.0
- _carbonIntensity = 0.0
- _carbonEmission = 0.0
}
}
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/PowerSourceTableReaderImpl.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/PowerSourceTableReaderImpl.kt
index 91918ea8..6a44d1ea 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/PowerSourceTableReaderImpl.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/PowerSourceTableReaderImpl.kt
@@ -22,7 +22,6 @@
package org.opendc.compute.simulator.telemetry.table
-import org.opendc.compute.carbon.CarbonTrace
import org.opendc.simulator.compute.power.SimPowerSource
import java.time.Duration
import java.time.Instant
@@ -33,7 +32,6 @@ import java.time.Instant
public class PowerSourceTableReaderImpl(
powerSource: SimPowerSource,
private val startTime: Duration = Duration.ofMillis(0),
- private val carbonTrace: CarbonTrace = CarbonTrace(null),
) : PowerSourceTableReader {
override fun copy(): PowerSourceTableReader {
val newPowerSourceTable =
@@ -84,8 +82,9 @@ public class PowerSourceTableReaderImpl(
private var _carbonIntensity = 0.0
override val carbonEmission: Double
- get() = _carbonEmission
+ get() = _carbonEmission - previousCarbonEmission
private var _carbonEmission = 0.0
+ private var previousCarbonEmission = 0.0
/**
* Record the next cycle.
@@ -95,10 +94,12 @@ public class PowerSourceTableReaderImpl(
_timestampAbsolute = now + startTime
_hostsConnected = 0
+
+ powerSource.updateCounters()
_powerDraw = powerSource.powerDraw
_energyUsage = powerSource.energyUsage
- _carbonIntensity = 0.0
- _carbonEmission = carbonIntensity * (energyUsage / 3600000.0)
+ _carbonIntensity = powerSource.carbonIntensity
+ _carbonEmission = powerSource.carbonEmission
}
/**
@@ -106,6 +107,7 @@ public class PowerSourceTableReaderImpl(
*/
override fun reset() {
previousEnergyUsage = _energyUsage
+ previousCarbonEmission = _carbonEmission
_hostsConnected = 0
_powerDraw = 0.0