From d97356cf696dedb6c26fc42d9d7c44a977264dcd Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Thu, 22 Sep 2022 22:39:33 +0200 Subject: refactor(compute): Pass failure model during workload evaluation This change updates the `ComputeServiceHelper` class to provide the failure model via a parameter to the `run` method instead of constructor parameter. This separates the construction of the topology from the simulation of the workload. --- .../main/kotlin/org/opendc/compute/workload/ComputeServiceHelper.kt | 4 ++-- .../src/main/kotlin/org/opendc/experiments/capelin/CapelinRunner.kt | 3 +-- .../kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt | 5 ++--- .../src/main/kotlin/org/opendc/web/runner/OpenDCRunner.kt | 3 +-- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeServiceHelper.kt b/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeServiceHelper.kt index 3be0217c..4c07b785 100644 --- a/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeServiceHelper.kt +++ b/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeServiceHelper.kt @@ -47,7 +47,6 @@ import kotlin.math.max * @param context [CoroutineContext] to run the simulation in. * @param clock [Clock] instance tracking simulation time. * @param scheduler [ComputeScheduler] implementation to use for the service. - * @param failureModel A failure model to use for injecting failures. * @param schedulingQuantum The scheduling quantum of the scheduler. */ public class ComputeServiceHelper( @@ -55,7 +54,6 @@ public class ComputeServiceHelper( private val clock: Clock, scheduler: ComputeScheduler, seed: Long, - private val failureModel: FailureModel? = null, schedulingQuantum: Duration = Duration.ofMinutes(5) ) : AutoCloseable { /** @@ -89,12 +87,14 @@ public class ComputeServiceHelper( * @param trace The trace to simulate. * @param servers A list to which the created servers is added. * @param submitImmediately A flag to indicate that the servers are scheduled immediately (so not at their start time). + * @param failureModel A failure model to use for injecting failures. * @param interference A flag to indicate that VM interference needs to be enabled. */ public suspend fun run( trace: List, servers: MutableList? = null, submitImmediately: Boolean = false, + failureModel: FailureModel? = null, interference: Boolean = false, ) { val injector = failureModel?.createInjector(context, clock, service, Random(random.nextLong())) 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 7be09ff5..98702b4c 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 @@ -74,7 +74,6 @@ public class CapelinRunner( clock, computeScheduler, seed, - failureModel ) val topology = clusterTopology(File(envPath, "${scenario.topology.name}.txt")) @@ -104,7 +103,7 @@ public class CapelinRunner( runner.apply(topology, optimize = true) // Run the workload trace - runner.run(vms, servers, interference = operationalPhenomena.hasInterference) + runner.run(vms, servers, failureModel = failureModel, interference = operationalPhenomena.hasInterference) // Stop the metric collection exporter?.close() diff --git a/opendc-experiments/opendc-experiments-capelin/src/test/kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt b/opendc-experiments/opendc-experiments-capelin/src/test/kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt index af846dd6..bf8c2758 100644 --- a/opendc-experiments/opendc-experiments-capelin/src/test/kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt +++ b/opendc-experiments/opendc-experiments-capelin/src/test/kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt @@ -226,8 +226,7 @@ class CapelinIntegrationTest { coroutineContext, clock, computeScheduler, - seed, - grid5000(Duration.ofDays(7)) + seed ) val topology = createTopology("single") val workload = createTestWorkload(0.25, seed) @@ -236,7 +235,7 @@ class CapelinIntegrationTest { try { simulator.apply(topology) - simulator.run(workload, servers) + simulator.run(workload, servers, failureModel = grid5000(Duration.ofDays(7))) val serviceMetrics = simulator.service.getSchedulerStats() println( diff --git a/opendc-web/opendc-web-runner/src/main/kotlin/org/opendc/web/runner/OpenDCRunner.kt b/opendc-web/opendc-web-runner/src/main/kotlin/org/opendc/web/runner/OpenDCRunner.kt index b7e550ef..570920f3 100644 --- a/opendc-web/opendc-web-runner/src/main/kotlin/org/opendc/web/runner/OpenDCRunner.kt +++ b/opendc-web/opendc-web-runner/src/main/kotlin/org/opendc/web/runner/OpenDCRunner.kt @@ -221,7 +221,6 @@ public class OpenDCRunner( clock, computeScheduler, seed = 0L, - failureModel ) val servers = mutableListOf() val reader = ComputeMetricReader(this, clock, simulator.service, servers, monitor) @@ -230,7 +229,7 @@ public class OpenDCRunner( // Instantiate the topology onto the simulator simulator.apply(topology) // Run workload trace - simulator.run(vms, servers, interference = phenomena.interference) + simulator.run(vms, servers, failureModel = failureModel, interference = phenomena.interference) val serviceMetrics = simulator.service.getSchedulerStats() logger.debug { -- cgit v1.2.3