diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-10-03 17:20:34 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-10-03 20:47:12 +0200 |
| commit | bd476d11ab24fe745bb54e97a11133706bb96cb1 (patch) | |
| tree | b5edaff69212986265f9edc620e40bb8695f11eb /opendc-experiments/opendc-experiments-capelin/src/main | |
| parent | 448b4cafe3c757812138a8ca7580975191ac2f9c (diff) | |
refactor(exp/compute): Remove Topology interface
This change removes the Topology interface from the
`opendc-experiments-compute` module, which was meant for provisioning
the experimental topology. Howerver, with the stateless `HostSpec`
class, it is not needed to resolve the topology everytime.
Diffstat (limited to 'opendc-experiments/opendc-experiments-capelin/src/main')
3 files changed, 34 insertions, 41 deletions
diff --git a/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/CapelinRunner.kt b/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/CapelinRunner.kt index e019af34..f1214b08 100644 --- a/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/CapelinRunner.kt +++ b/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/CapelinRunner.kt @@ -61,7 +61,7 @@ public class CapelinRunner( Provisioner(coroutineContext, clock, seed).use { provisioner -> provisioner.runSteps( setupComputeService(serviceDomain, { createComputeScheduler(scenario.allocationPolicy, Random(it.seeder.nextLong())) }), - setupHosts(serviceDomain, topology.resolve(), optimize = true) + setupHosts(serviceDomain, topology, optimize = true) ) if (outputPath != null) { diff --git a/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/model/Topology.kt b/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/model/Topology.kt index fe16a294..c90194ce 100644 --- a/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/model/Topology.kt +++ b/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/model/Topology.kt @@ -23,6 +23,6 @@ package org.opendc.experiments.capelin.model /** - * The topology topology on which we test the workload. + * The topology on which we simulate the workload. */ public data class Topology(val name: String) diff --git a/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/topology/TopologyFactories.kt b/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/topology/TopologyFactories.kt index d152a6db..054adfcd 100644 --- a/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/topology/TopologyFactories.kt +++ b/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/topology/TopologyFactories.kt @@ -24,7 +24,6 @@ package org.opendc.experiments.capelin.topology import org.opendc.experiments.compute.topology.HostSpec -import org.opendc.experiments.compute.topology.Topology import org.opendc.simulator.compute.model.MachineModel import org.opendc.simulator.compute.model.MemoryUnit import org.opendc.simulator.compute.model.ProcessingNode @@ -43,61 +42,55 @@ import kotlin.math.roundToLong private val reader = ClusterSpecReader() /** - * Construct a [Topology] from the specified [file]. + * Construct a topology from the specified [file]. */ fun clusterTopology( file: File, powerModel: PowerModel = LinearPowerModel(350.0, idlePower = 200.0), random: Random = Random(0) -): Topology = clusterTopology(reader.read(file), powerModel, random) +): List<HostSpec> { + return clusterTopology(reader.read(file), powerModel, random) +} /** - * Construct a [Topology] from the specified [input]. + * Construct a topology from the specified [input]. */ fun clusterTopology( input: InputStream, powerModel: PowerModel = LinearPowerModel(350.0, idlePower = 200.0), random: Random = Random(0) -): Topology = clusterTopology(reader.read(input), powerModel, random) +): List<HostSpec> { + return clusterTopology(reader.read(input), powerModel, random) +} /** - * Construct a [Topology] from the given list of [clusters]. + * Construct a topology from the given list of [clusters]. */ -fun clusterTopology( - clusters: List<ClusterSpec>, - powerModel: PowerModel, - random: Random = Random(0) -): Topology { - return object : Topology { - override fun resolve(): List<HostSpec> { - val hosts = mutableListOf<HostSpec>() - for (cluster in clusters) { - val cpuSpeed = cluster.cpuSpeed - val memoryPerHost = cluster.memCapacityPerHost.roundToLong() - - val unknownProcessingNode = ProcessingNode("unknown", "unknown", "unknown", cluster.cpuCountPerHost) - val unknownMemoryUnit = MemoryUnit("unknown", "unknown", -1.0, memoryPerHost) - val machineModel = MachineModel( - List(cluster.cpuCountPerHost) { coreId -> ProcessingUnit(unknownProcessingNode, coreId, cpuSpeed) }, - listOf(unknownMemoryUnit) - ) - - repeat(cluster.hostCount) { - val spec = HostSpec( - UUID(random.nextLong(), it.toLong()), - "node-${cluster.name}-$it", - mapOf("cluster" to cluster.id), - machineModel, - SimplePowerDriver(powerModel) - ) +fun clusterTopology(clusters: List<ClusterSpec>, powerModel: PowerModel, random: Random = Random(0)): List<HostSpec> { + return clusters.flatMap { it.toHostSpecs(random, powerModel) } +} - hosts += spec - } - } +/** + * Helper method to convert a [ClusterSpec] into a list of [HostSpec]s. + */ +private fun ClusterSpec.toHostSpecs(random: Random, powerModel: PowerModel): List<HostSpec> { + val cpuSpeed = cpuSpeed + val memoryPerHost = memCapacityPerHost.roundToLong() - return hosts - } + val unknownProcessingNode = ProcessingNode("unknown", "unknown", "unknown", cpuCountPerHost) + val unknownMemoryUnit = MemoryUnit("unknown", "unknown", -1.0, memoryPerHost) + val machineModel = MachineModel( + List(cpuCountPerHost) { coreId -> ProcessingUnit(unknownProcessingNode, coreId, cpuSpeed) }, + listOf(unknownMemoryUnit) + ) - override fun toString(): String = "ClusterSpecTopology" + return List(hostCount) { + HostSpec( + UUID(random.nextLong(), it.toLong()), + "node-$name-$it", + mapOf("cluster" to id), + machineModel, + SimplePowerDriver(powerModel) + ) } } |
