diff options
| author | Dante Niewenhuis <d.niewenhuis@hotmail.com> | 2025-03-18 07:26:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-18 07:26:35 +0100 |
| commit | 97db8e0351b9451ece8fd16c25ca0588ec71a2ab (patch) | |
| tree | e72f32df2b12677e9ae2f9997b226c8da97e56e4 /opendc-compute/opendc-compute-simulator/src/main | |
| parent | 7dc2639a7fcdf51ef789f4af2e3afff11438be6e (diff) | |
Performance updates (#314)
Diffstat (limited to 'opendc-compute/opendc-compute-simulator/src/main')
3 files changed, 34 insertions, 34 deletions
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/host/SimHost.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/host/SimHost.kt index 132ad227..53fafe5f 100644 --- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/host/SimHost.kt +++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/host/SimHost.kt @@ -35,8 +35,8 @@ import org.opendc.simulator.compute.cpu.CpuPowerModel import org.opendc.simulator.compute.machine.SimMachine import org.opendc.simulator.compute.models.MachineModel import org.opendc.simulator.compute.models.MemoryUnit +import org.opendc.simulator.engine.engine.FlowEngine import org.opendc.simulator.engine.graph.FlowDistributor -import org.opendc.simulator.engine.graph.FlowGraph import java.time.Duration import java.time.Instant import java.time.InstantSource @@ -56,7 +56,7 @@ public class SimHost( private val name: String, private val clusterName: String, private val clock: InstantSource, - private val graph: FlowGraph, + private val engine: FlowEngine, private val machineModel: MachineModel, private val cpuPowerModel: CpuPowerModel, private val powerDistributor: FlowDistributor, @@ -126,7 +126,7 @@ public class SimHost( this.simMachine = SimMachine( - this.graph, + this.engine, this.machineModel, this.powerDistributor, this.cpuPowerModel, 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 83968d35..e2bdd960 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 @@ -29,8 +29,8 @@ import org.opendc.compute.simulator.service.ServiceTask import org.opendc.compute.simulator.telemetry.GuestCpuStats import org.opendc.compute.simulator.telemetry.GuestSystemStats import org.opendc.simulator.compute.machine.SimMachine -import org.opendc.simulator.compute.machine.VirtualMachine import org.opendc.simulator.compute.workload.ChainWorkload +import org.opendc.simulator.compute.workload.SimChainWorkload import org.opendc.simulator.compute.workload.trace.TraceFragment import org.opendc.simulator.compute.workload.trace.TraceWorkload import org.opendc.simulator.compute.workload.trace.scaling.NoDelayScaling @@ -58,9 +58,9 @@ public class Guest( private set /** - * The [VirtualMachine] on which the task is currently running + * The [SimChainWorkload] on which the task is currently running */ - public var virtualMachine: VirtualMachine? = null + public var simChainWorkload: SimChainWorkload? = null private var uptime = 0L private var downtime = 0L @@ -90,7 +90,7 @@ public class Guest( * Launch the guest on the simulated Virtual machine */ private fun doStart() { - assert(virtualMachine == null) { "Concurrent job is already running" } + assert(simChainWorkload == null) { "Concurrent job is already running" } onStart() @@ -114,7 +114,12 @@ public class Guest( scalingPolicy, ) - if (task.workload is TraceWorkload) { + if (task.workload is ChainWorkload) { + simChainWorkload = + simMachine.startWorkload(task.workload as ChainWorkload) { cause -> + onStop(if (cause != null) TaskState.FAILED else TaskState.COMPLETED) + } + } else { val newChainWorkload = ChainWorkload( ArrayList(listOf(task.workload)), @@ -123,15 +128,10 @@ public class Guest( task.workload.checkpointIntervalScaling, ) - virtualMachine = + simChainWorkload = simMachine.startWorkload(newChainWorkload) { cause -> onStop(if (cause != null) TaskState.FAILED else TaskState.COMPLETED) } - } else { - virtualMachine = - simMachine.startWorkload(task.workload) { cause -> - onStop(if (cause != null) TaskState.FAILED else TaskState.COMPLETED) - } } } @@ -160,15 +160,15 @@ public class Guest( * Attempt to stop the task and put it into [target] state. */ private fun doStop(target: TaskState) { - assert(virtualMachine != null) { "Invalid job state" } - val virtualMachine = this.virtualMachine ?: return + assert(simChainWorkload != null) { "Invalid job state" } + val virtualMachine = this.simChainWorkload ?: return if (target == TaskState.FAILED) { - virtualMachine.shutdown(Exception("Task has failed")) + virtualMachine.stopWorkload(Exception("Task has failed")) } else { - virtualMachine.shutdown() + virtualMachine.stopWorkload() } - this.virtualMachine = null + this.simChainWorkload = null this.state = target } @@ -236,8 +236,8 @@ public class Guest( * Obtain the CPU statistics of this guest. */ public fun getCpuStats(): GuestCpuStats { - virtualMachine!!.updateCounters(this.clock.millis()) - val counters = virtualMachine!!.performanceCounters + simChainWorkload!!.updateCounters(this.clock.millis()) + val counters = simChainWorkload!!.performanceCounters return GuestCpuStats( counters.cpuActiveTime / 1000L, 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 211f33fe..68e263f8 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 @@ -34,6 +34,7 @@ import org.opendc.simulator.compute.power.batteries.BatteryAggregator import org.opendc.simulator.compute.power.batteries.SimBattery import org.opendc.simulator.engine.engine.FlowEngine import org.opendc.simulator.engine.graph.FlowDistributor +import org.opendc.simulator.engine.graph.FlowEdge /** * A [ProvisioningStep] that provisions a list of hosts for a [ComputeService]. @@ -56,36 +57,35 @@ public class HostsProvisioningStep internal constructor( val simPowerSources = mutableListOf<SimPowerSource>() val engine = FlowEngine.create(ctx.dispatcher) - val graph = engine.newGraph() for (cluster in clusterSpecs) { // Create the Power Source to which hosts are connected // Create Power Source - val simPowerSource = SimPowerSource(graph, cluster.powerSource.totalPower.toDouble(), cluster.powerSource.name, cluster.name) + val simPowerSource = SimPowerSource(engine, cluster.powerSource.totalPower.toDouble(), cluster.powerSource.name, cluster.name) simPowerSources.add(simPowerSource) service.addPowerSource(simPowerSource) - val hostDistributor = FlowDistributor(graph) + val hostDistributor = FlowDistributor(engine) val carbonFragments = getCarbonFragments(cluster.powerSource.carbonTracePath) var carbonModel: CarbonModel? = null // Create Carbon Model if (carbonFragments != null) { - carbonModel = CarbonModel(graph, carbonFragments, startTime) + carbonModel = CarbonModel(engine, carbonFragments, startTime) carbonModel.addReceiver(simPowerSource) } if (cluster.battery != null) { // Create Battery Distributor - val batteryDistributor = FlowDistributor(graph) - graph.addEdge(batteryDistributor, simPowerSource) + val batteryDistributor = FlowDistributor(engine) + FlowEdge(batteryDistributor, simPowerSource) // Create Battery val battery = SimBattery( - graph, + engine, cluster.battery!!.capacity, cluster.battery!!.chargingSpeed, cluster.battery!!.initialCharge, @@ -94,26 +94,26 @@ public class HostsProvisioningStep internal constructor( cluster.battery!!.embodiedCarbon, cluster.battery!!.expectedLifetime, ) - graph.addEdge(battery, batteryDistributor) + FlowEdge(battery, batteryDistributor) // Create Aggregator - val batteryAggregator = BatteryAggregator(graph, battery, batteryDistributor) + val batteryAggregator = BatteryAggregator(engine, battery, batteryDistributor) val batteryPolicy = createSimBatteryPolicy( cluster.battery!!.batteryPolicy, - graph, + engine, battery, batteryAggregator, ) carbonModel?.addReceiver(batteryPolicy) - graph.addEdge(hostDistributor, batteryAggregator) + FlowEdge(hostDistributor, batteryAggregator) service.addBattery(battery) } else { - graph.addEdge(hostDistributor, simPowerSource) + FlowEdge(hostDistributor, simPowerSource) } // Create hosts, they are connected to the powerMux when SimMachine is created @@ -123,7 +123,7 @@ public class HostsProvisioningStep internal constructor( hostSpec.name, cluster.name, ctx.dispatcher.timeSource, - graph, + engine, hostSpec.model, hostSpec.cpuPowerModel, hostDistributor, |
