summaryrefslogtreecommitdiff
path: root/simulator/opendc-runner-web/src/main
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-04-15 14:01:54 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-04-15 14:25:23 +0200
commit288c6c18c24b27dee230d31f0dd036b199722302 (patch)
tree45dc681861922572edf387cd2b2b12550d8c3baa /simulator/opendc-runner-web/src/main
parent890dd87376f0d131292e3cdc685ab13192d11634 (diff)
exp: Re-use topology across repeats
This change modifies the web runner to construct the topology only once per repeat, given that the construction does not depend on the repeat number.
Diffstat (limited to 'simulator/opendc-runner-web/src/main')
-rw-r--r--simulator/opendc-runner-web/src/main/kotlin/org/opendc/runner/web/Main.kt15
-rw-r--r--simulator/opendc-runner-web/src/main/kotlin/org/opendc/runner/web/TopologyParser.kt16
2 files changed, 18 insertions, 13 deletions
diff --git a/simulator/opendc-runner-web/src/main/kotlin/org/opendc/runner/web/Main.kt b/simulator/opendc-runner-web/src/main/kotlin/org/opendc/runner/web/Main.kt
index a368dfee..31f7876e 100644
--- a/simulator/opendc-runner-web/src/main/kotlin/org/opendc/runner/web/Main.kt
+++ b/simulator/opendc-runner-web/src/main/kotlin/org/opendc/runner/web/Main.kt
@@ -31,7 +31,6 @@ import com.mongodb.MongoClientSettings
import com.mongodb.MongoCredential
import com.mongodb.ServerAddress
import com.mongodb.client.MongoClients
-import com.mongodb.client.MongoCollection
import com.mongodb.client.MongoDatabase
import com.mongodb.client.model.Filters
import io.opentelemetry.api.metrics.MeterProvider
@@ -51,6 +50,7 @@ import org.opendc.experiments.capelin.*
import org.opendc.experiments.capelin.model.Workload
import org.opendc.experiments.capelin.trace.Sc20ParquetTraceReader
import org.opendc.experiments.capelin.trace.Sc20RawParquetTraceReader
+import org.opendc.format.environment.EnvironmentReader
import org.opendc.format.trace.sc20.Sc20PerformanceInterferenceReader
import org.opendc.simulator.utils.DelayControllerClockAdapter
import org.opendc.telemetry.sdk.toOtelClock
@@ -159,7 +159,7 @@ public class RunnerCli : CliktCommand(name = "runner") {
/**
* Run a single scenario.
*/
- private suspend fun runScenario(portfolio: Document, scenario: Document, topologies: MongoCollection<Document>): List<WebExperimentMonitor.Result> {
+ private suspend fun runScenario(portfolio: Document, scenario: Document, topologyParser: TopologyParser): List<WebExperimentMonitor.Result> {
val id = scenario.getObjectId("_id")
logger.info { "Constructing performance interference model" }
@@ -182,11 +182,13 @@ public class RunnerCli : CliktCommand(name = "runner") {
}
val targets = portfolio.get("targets", Document::class.java)
+ val topologyId = scenario.getEmbedded(listOf("topology", "topologyId"), ObjectId::class.java)
+ val environment = topologyParser.read(topologyId)
val results = (0 until targets.getInteger("repeatsPerScenario")).map {
logger.info { "Starting repeat $it" }
withTimeout(runTimeout * 1000) {
- runRepeat(scenario, it, topologies, traceReader, performanceInterferenceReader)
+ runRepeat(scenario, it, environment, traceReader, performanceInterferenceReader)
}
}
@@ -201,7 +203,7 @@ public class RunnerCli : CliktCommand(name = "runner") {
private suspend fun runRepeat(
scenario: Document,
repeat: Int,
- topologies: MongoCollection<Document>,
+ environment: EnvironmentReader,
traceReader: Sc20RawParquetTraceReader,
performanceInterferenceReader: Sc20PerformanceInterferenceReader?
): WebExperimentMonitor.Result {
@@ -274,8 +276,6 @@ public class RunnerCli : CliktCommand(name = "runner") {
Workload(workloadName, workloadFraction),
seed
)
- val topologyId = scenario.getEmbedded(listOf("topology", "topologyId"), ObjectId::class.java)
- val environment = TopologyParser(topologies, topologyId)
val failureFrequency = if (operational.getBoolean("failuresEnabled", false)) 24.0 * 7 else 0.0
withComputeService(clock, meterProvider, environment, allocationPolicy) { scheduler ->
@@ -326,6 +326,7 @@ public class RunnerCli : CliktCommand(name = "runner") {
val manager = ScenarioManager(database.getCollection("scenarios"))
val portfolios = database.getCollection("portfolios")
val topologies = database.getCollection("topologies")
+ val topologyParser = TopologyParser(topologies)
logger.info { "Watching for queued scenarios" }
@@ -357,7 +358,7 @@ public class RunnerCli : CliktCommand(name = "runner") {
try {
val portfolio = portfolios.find(Filters.eq("_id", scenario.getObjectId("portfolioId"))).first()!!
- val results = runScenario(portfolio, scenario, topologies)
+ val results = runScenario(portfolio, scenario, topologyParser)
logger.info { "Writing results to database" }
diff --git a/simulator/opendc-runner-web/src/main/kotlin/org/opendc/runner/web/TopologyParser.kt b/simulator/opendc-runner-web/src/main/kotlin/org/opendc/runner/web/TopologyParser.kt
index 1683cdb8..2dd63340 100644
--- a/simulator/opendc-runner-web/src/main/kotlin/org/opendc/runner/web/TopologyParser.kt
+++ b/simulator/opendc-runner-web/src/main/kotlin/org/opendc/runner/web/TopologyParser.kt
@@ -42,9 +42,12 @@ import java.util.*
/**
* A helper class that converts the MongoDB topology into an OpenDC environment.
*/
-public class TopologyParser(private val collection: MongoCollection<Document>, private val id: ObjectId) : EnvironmentReader {
+public class TopologyParser(private val collection: MongoCollection<Document>) {
- public override fun read(): List<MachineDef> {
+ /**
+ * Parse the topology from the specified [id].
+ */
+ public fun read(id: ObjectId): EnvironmentReader {
val nodes = mutableListOf<MachineDef>()
val random = Random(0)
@@ -78,16 +81,17 @@ public class TopologyParser(private val collection: MongoCollection<Document>, p
"node-$clusterId-$position",
mapOf("cluster" to clusterId),
SimMachineModel(processors, memoryUnits),
- LinearPowerModel(2 * energyConsumptionW, .5)
+ LinearPowerModel(2 * energyConsumptionW, energyConsumptionW * 0.5)
)
)
}
- return nodes
+ return object : EnvironmentReader {
+ override fun read(): List<MachineDef> = nodes
+ override fun close() {}
+ }
}
- override fun close() {}
-
/**
* Fetch the metadata of the topology.
*/