diff options
| author | Dante Niewenhuis <d.niewenhuis@hotmail.com> | 2024-11-26 11:09:21 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-26 11:09:21 +0100 |
| commit | ec73210b675fd90568c5193e6ae6ef82ce81be6c (patch) | |
| tree | 89b530b53898752f7800e5109548412b84fcd375 /opendc-simulator/opendc-simulator-compute/src/main/java | |
| parent | 698a64615d0eef8994fc1eaf0a3b71da194e1dcd (diff) | |
Streamlined the FlowNetwork for better performance (#273)
Diffstat (limited to 'opendc-simulator/opendc-simulator-compute/src/main/java')
6 files changed, 55 insertions, 67 deletions
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/cpu/SimCpu.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/cpu/SimCpu.java index 24627a9c..18214172 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/cpu/SimCpu.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/cpu/SimCpu.java @@ -46,7 +46,7 @@ public final class SimCpu extends FlowNode implements FlowSupplier, FlowConsumer private double maxCapacity; - private PerformanceCounters performanceCounters = new PerformanceCounters(); + private final PerformanceCounters performanceCounters = new PerformanceCounters(); private long lastCounterUpdate; private final double cpuFrequencyInv; @@ -122,22 +122,20 @@ public final class SimCpu extends FlowNode implements FlowSupplier, FlowConsumer public long onUpdate(long now) { updateCounters(now); + this.currentCpuUtilization = this.currentCpuDemand / this.maxCapacity; + // Calculate Power Demand and send to PSU - // TODO: look at the double / double thing double powerDemand = this.cpuPowerModel.computePower(this.currentCpuUtilization); if (powerDemand != this.currentPowerDemand) { this.pushDemand(this.psuEdge, powerDemand); - this.currentPowerDemand = powerDemand; } // Calculate the amount of cpu this can provide - // TODO: This should be based on the provided power double cpuSupply = this.currentCpuDemand; if (cpuSupply != this.currentCpuSupplied) { this.pushSupply(this.muxEdge, cpuSupply); - this.currentCpuSupplied = cpuSupply; } return Long.MAX_VALUE; @@ -183,6 +181,8 @@ public final class SimCpu extends FlowNode implements FlowSupplier, FlowConsumer */ @Override public void pushDemand(FlowEdge supplierEdge, double newPowerDemand) { + updateCounters(); + this.currentPowerDemand = newPowerDemand; this.psuEdge.pushDemand(newPowerDemand); } @@ -205,7 +205,12 @@ public final class SimCpu extends FlowNode implements FlowSupplier, FlowConsumer this.currentCpuDemand = newCpuDemand; this.currentCpuUtilization = this.currentCpuDemand / this.maxCapacity; - this.invalidate(); + // Calculate Power Demand and send to PSU + double powerDemand = this.cpuPowerModel.computePower(this.currentCpuUtilization); + + if (powerDemand != this.currentPowerDemand) { + this.pushDemand(this.psuEdge, powerDemand); + } } /** @@ -217,7 +222,12 @@ public final class SimCpu extends FlowNode implements FlowSupplier, FlowConsumer updateCounters(); this.currentPowerSupplied = newPowerSupply; - this.invalidate(); + // Calculate the amount of cpu this can provide + double cpuSupply = this.currentCpuDemand; + + if (cpuSupply != this.currentCpuSupplied) { + this.pushSupply(this.muxEdge, cpuSupply); + } } /** @@ -234,6 +244,8 @@ public final class SimCpu extends FlowNode implements FlowSupplier, FlowConsumer @Override public void addSupplierEdge(FlowEdge supplierEdge) { this.psuEdge = supplierEdge; + + this.invalidate(); } /** diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/SimMachine.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/SimMachine.java index 4602223c..c7caa63f 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/SimMachine.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/SimMachine.java @@ -25,7 +25,6 @@ package org.opendc.simulator.compute.machine; import java.time.InstantSource; import java.util.function.Consumer; import org.opendc.simulator.Multiplexer; -import org.opendc.simulator.compute.cpu.CpuPowerModel; import org.opendc.simulator.compute.cpu.SimCpu; import org.opendc.simulator.compute.memory.Memory; import org.opendc.simulator.compute.models.MachineModel; @@ -48,7 +47,7 @@ public class SimMachine { private SimPsu psu; private Memory memory; - private Consumer<Exception> completion; + private final Consumer<Exception> completion; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Basic Getters and Setters @@ -112,11 +111,7 @@ public class SimMachine { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public SimMachine( - FlowGraph graph, - MachineModel machineModel, - CpuPowerModel cpuPowerModel, - Multiplexer powerMux, - Consumer<Exception> completion) { + FlowGraph graph, MachineModel machineModel, Multiplexer powerMux, Consumer<Exception> completion) { this.graph = graph; this.machineModel = machineModel; this.clock = graph.getEngine().getClock(); diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/VirtualMachine.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/VirtualMachine.java index 0557165b..15a1b1c4 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/VirtualMachine.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/VirtualMachine.java @@ -36,7 +36,7 @@ import org.opendc.simulator.engine.FlowSupplier; A virtual Machine created to run a single workload */ public class VirtualMachine extends FlowNode implements FlowConsumer, FlowSupplier { - private SimMachine machine; + private final SimMachine machine; private SimWorkload activeWorkload; diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPowerSource.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPowerSource.java index a219d4e6..ea500c81 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPowerSource.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPowerSource.java @@ -126,12 +126,6 @@ public final class SimPowerSource extends FlowNode implements FlowSupplier { @Override public long onUpdate(long now) { - updateCounters(); - double powerSupply = this.powerDemand; - - if (powerSupply != this.powerSupplied) { - this.pushSupply(this.muxEdge, powerSupply); - } return Long.MAX_VALUE; } @@ -163,14 +157,17 @@ public final class SimPowerSource extends FlowNode implements FlowSupplier { @Override public void handleDemand(FlowEdge consumerEdge, double newPowerDemand) { - this.powerDemand = newPowerDemand; - this.invalidate(); + + double powerSupply = this.powerDemand; + + if (powerSupply != this.powerSupplied) { + this.pushSupply(this.muxEdge, powerSupply); + } } @Override public void pushSupply(FlowEdge consumerEdge, double newSupply) { - this.powerSupplied = newSupply; consumerEdge.pushSupply(newSupply); } diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimChainWorkload.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimChainWorkload.java index f91c363d..5b7c10bb 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimChainWorkload.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimChainWorkload.java @@ -170,7 +170,7 @@ final class SimChainWorkload extends SimWorkload implements FlowSupplier { /** * Add connection to the active workload * - * @param consumerEdge + * @param consumerEdge The edge to the workload */ @Override public void addConsumerEdge(FlowEdge consumerEdge) { @@ -179,7 +179,8 @@ final class SimChainWorkload extends SimWorkload implements FlowSupplier { /** * Add Connection to the cpuMux - * @param supplierEdge + * + * @param supplierEdge The edge to the cpuMux */ @Override public void addSupplierEdge(FlowEdge supplierEdge) { @@ -190,53 +191,48 @@ final class SimChainWorkload extends SimWorkload implements FlowSupplier { /** * Push demand to the cpuMux * - * @param supplierEdge - * @param newDemand + * @param supplierEdge The edge to the cpuMux + * @param newDemand new demand to sent to the cpu */ @Override public void pushDemand(FlowEdge supplierEdge, double newDemand) { + + this.demand = newDemand; this.machineEdge.pushDemand(newDemand); } /** * Push supply to the workload * - * @param consumerEdge - * @param newSupply + * @param consumerEdge The edge to the cpuMux + * @param newSupply new supply to sent to the workload */ @Override public void pushSupply(FlowEdge consumerEdge, double newSupply) { + + this.supply = newSupply; this.workloadEdge.pushSupply(newSupply); } /** * Handle new demand coming from the workload * - * @param consumerEdge - * @param newDemand + * @param consumerEdge The edge to the workload + * @param newDemand new demand coming from the workload */ @Override public void handleDemand(FlowEdge consumerEdge, double newDemand) { - if (newDemand == this.demand) { - return; - } - - this.demand = newDemand; this.pushDemand(this.machineEdge, newDemand); } /** * Handle new supply coming from the cpuMux * - * @param supplierEdge - * @param newSupply + * @param supplierEdge The edge to the cpuMux + * @param newSupply The new supply that is sent to the workload */ @Override public void handleSupply(FlowEdge supplierEdge, double newSupply) { - if (newSupply == this.supply) { - return; - } - this.pushSupply(this.machineEdge, newSupply); } @@ -245,7 +241,7 @@ final class SimChainWorkload extends SimWorkload implements FlowSupplier { * If there is a next workload available, start this workload * Otherwise, close this SimChainWorkload * - * @param consumerEdge + * @param consumerEdge The edge to the active workload */ @Override public void removeConsumerEdge(FlowEdge consumerEdge) { @@ -270,18 +266,10 @@ final class SimChainWorkload extends SimWorkload implements FlowSupplier { * Handle the removal of the connection to the cpuMux * When this happens, close the SimChainWorkload * - * @param supplierEdge + * @param supplierEdge The edge to the cpuMux */ @Override public void removeSupplierEdge(FlowEdge supplierEdge) { this.stopWorkload(); } - - @SuppressWarnings("unchecked") - private static <T extends Throwable> void tryThrow(Throwable e) throws T { - if (e == null) { - return; - } - throw (T) e; - } } diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTraceWorkload.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTraceWorkload.java index b269564d..59994fe6 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTraceWorkload.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTraceWorkload.java @@ -40,9 +40,7 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer { private double currentDemand; private double currentSupply; - private long checkpointInterval; private long checkpointDuration; - private double checkpointIntervalScaling; private TraceWorkload snapshot; @@ -88,9 +86,7 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer { super(((FlowNode) supplier).getGraph()); this.snapshot = workload; - this.checkpointInterval = workload.getCheckpointInterval(); this.checkpointDuration = workload.getCheckpointDuration(); - this.checkpointIntervalScaling = workload.getCheckpointIntervalScaling(); this.remainingFragments = new LinkedList<>(workload.getFragments()); this.fragmentIndex = 0; @@ -98,7 +94,7 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer { graph.addEdge(this, supplier); this.currentFragment = this.getNextFragment(); - pushDemand(machineEdge, (double) this.currentFragment.cpuUsage()); + pushDemand(machineEdge, this.currentFragment.cpuUsage()); this.startOfFragment = now; } @@ -135,7 +131,7 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer { this.startOfFragment = now - passedTime; // Change the cpu Usage to the new Fragment - pushDemand(machineEdge, (double) this.currentFragment.cpuUsage()); + pushDemand(machineEdge, this.currentFragment.cpuUsage()); // Return the time when the current fragment will complete return this.startOfFragment + duration; @@ -163,7 +159,7 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer { /** * Create a new snapshot based on the current status of the workload. - * @param now + * @param now Moment on which the snapshot is made in milliseconds */ public void makeSnapshot(long now) { @@ -190,7 +186,7 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer { this.fragmentIndex = -1; this.currentFragment = getNextFragment(); - pushDemand(this.machineEdge, (double) this.currentFragment.cpuUsage()); + pushDemand(this.machineEdge, this.currentFragment.cpuUsage()); this.startOfFragment = now; this.invalidate(); @@ -203,8 +199,8 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer { /** * Handle updates in supply from the Virtual Machine * - * @param supplierEdge - * @param newSupply + * @param supplierEdge edge to the VM on which this is running + * @param newSupply The new demand that needs to be sent to the VM */ @Override public void handleSupply(FlowEdge supplierEdge, double newSupply) { @@ -218,8 +214,8 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer { /** * Push a new demand to the Virtual Machine * - * @param supplierEdge - * @param newDemand + * @param supplierEdge edge to the VM on which this is running + * @param newDemand The new demand that needs to be sent to the VM */ @Override public void pushDemand(FlowEdge supplierEdge, double newDemand) { @@ -234,7 +230,7 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer { /** * Add the connection to the Virtual Machine * - * @param supplierEdge + * @param supplierEdge edge to the VM on which this is running */ @Override public void addSupplierEdge(FlowEdge supplierEdge) { @@ -245,7 +241,7 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer { * Handle the removal of the connection to the Virtual Machine * When the connection to the Virtual Machine is removed, the SimTraceWorkload is removed * - * @param supplierEdge + * @param supplierEdge edge to the VM on which this is running */ @Override public void removeSupplierEdge(FlowEdge supplierEdge) { |
