From 97db8e0351b9451ece8fd16c25ca0588ec71a2ab Mon Sep 17 00:00:00 2001 From: Dante Niewenhuis Date: Tue, 18 Mar 2025 07:26:35 +0100 Subject: Performance updates (#314) --- .../opendc/compute/topology/TopologyFactories.kt | 23 +++++++++++----------- .../opendc/compute/topology/specs/TopologySpecs.kt | 12 +++++------ 2 files changed, 17 insertions(+), 18 deletions(-) (limited to 'opendc-compute/opendc-compute-topology/src') diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt index a20bc2c2..cc2c4b4e 100644 --- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt +++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt @@ -44,10 +44,10 @@ import java.io.InputStream private val reader = TopologyReader() // Lists used to make sure all cluster, host, power source and battery have unique names -private val clusterNames: ArrayList = ArrayList() -private val hostNames: ArrayList = ArrayList() -private val powerSourceNames: ArrayList = ArrayList() -private val batteryNames: ArrayList = ArrayList() +private val clusterNames: HashMap = HashMap() +private val hostNames: HashMap = HashMap() +private val powerSourceNames: HashMap = HashMap() +private val batteryNames: HashMap = HashMap() /** * Create a unique name for the specified [name] that is not already in the [names] list. @@ -57,20 +57,19 @@ private val batteryNames: ArrayList = ArrayList() */ private fun createUniqueName( name: String, - names: ArrayList, + names: MutableMap, ): String { if (name !in names) { - names.add(name) + names[name] = 0 return name } - var i = 0 - var newName = "$name-$i" - while (newName in names) { - newName = "$name-${++i}" - } + val latestValue = names[name] + + val newName = "$name-$latestValue" + + names[name] = latestValue!! + 1 - names.add(newName) return newName } diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt index 3d8b63dc..920d8373 100644 --- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt +++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt @@ -34,7 +34,7 @@ import org.opendc.simulator.compute.power.batteries.policy.DoubleThresholdBatter import org.opendc.simulator.compute.power.batteries.policy.RunningMeanBatteryPolicy import org.opendc.simulator.compute.power.batteries.policy.RunningMeanPlusBatteryPolicy import org.opendc.simulator.compute.power.batteries.policy.SingleThresholdBatteryPolicy -import org.opendc.simulator.engine.graph.FlowGraph +import org.opendc.simulator.engine.engine.FlowEngine /** * Definition of a Topology modeled in the simulation. @@ -236,21 +236,21 @@ public data class RunningQuartilesPolicyJSONSpec( public fun createSimBatteryPolicy( batterySpec: BatteryPolicyJSONSpec, - graph: FlowGraph, + engine: FlowEngine, battery: SimBattery, batteryAggregator: BatteryAggregator, ): BatteryPolicy { return when (batterySpec) { is SingleBatteryPolicyJSONSpec -> SingleThresholdBatteryPolicy( - graph, + engine, battery, batteryAggregator, batterySpec.carbonThreshold, ) is DoubleBatteryPolicyJSONSpec -> DoubleThresholdBatteryPolicy( - graph, + engine, battery, batteryAggregator, batterySpec.lowerThreshold, @@ -258,7 +258,7 @@ public fun createSimBatteryPolicy( ) is RunningMeanPolicyJSONSpec -> RunningMeanBatteryPolicy( - graph, + engine, battery, batteryAggregator, batterySpec.startingThreshold, @@ -266,7 +266,7 @@ public fun createSimBatteryPolicy( ) is RunningMeanPlusPolicyJSONSpec -> RunningMeanPlusBatteryPolicy( - graph, + engine, battery, batteryAggregator, batterySpec.startingThreshold, -- cgit v1.2.3