From 1c0568c31d60d4e690b4b9aec2e14f660b72a5c8 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Wed, 21 Apr 2021 14:30:55 +0200 Subject: simulator: Introduce SimulationCoroutineDispatcher This change introduces the SimulationCoroutineDispatcher implementation which replaces the TestCoroutineDispatcher for running single-threaded simulations. Previously, we used the TestCoroutineDispatcher from the kotlinx-coroutines-test modules for running simulations. However, this module is aimed at coroutine tests and not at simulations. In particular, having to construct a Clock object each time for the TestCoroutineDispatcher caused a lot of unnecessary lines. With the new approach, the SimulationCoroutineDispatcher automatically exposes a usable Clock object. In addition to ergonomic benefits, the SimulationCoroutineDispatcher is much faster than the TestCoroutineDispatcher due to the assumption that simulations run in only a single thread. As a result, the dispatcher does not need to perform synchronization and can use the fast PriorityQueue implementation. --- .../kotlin/org/opendc/experiments/serverless/ServerlessExperiment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'simulator/opendc-experiments/opendc-experiments-serverless20') diff --git a/simulator/opendc-experiments/opendc-experiments-serverless20/src/main/kotlin/org/opendc/experiments/serverless/ServerlessExperiment.kt b/simulator/opendc-experiments/opendc-experiments-serverless20/src/main/kotlin/org/opendc/experiments/serverless/ServerlessExperiment.kt index 757617f8..5967c2d9 100644 --- a/simulator/opendc-experiments/opendc-experiments-serverless20/src/main/kotlin/org/opendc/experiments/serverless/ServerlessExperiment.kt +++ b/simulator/opendc-experiments/opendc-experiments-serverless20/src/main/kotlin/org/opendc/experiments/serverless/ServerlessExperiment.kt @@ -43,7 +43,7 @@ import org.opendc.simulator.compute.SimMachineModel import org.opendc.simulator.compute.model.MemoryUnit import org.opendc.simulator.compute.model.ProcessingNode import org.opendc.simulator.compute.model.ProcessingUnit -import org.opendc.simulator.utils.DelayControllerClockAdapter +import org.opendc.simulator.core.DelayControllerClockAdapter import org.opendc.telemetry.sdk.toOtelClock import java.io.File import java.util.* -- cgit v1.2.3 From 62678b2890a7f3640836b99ca2fec9efd7485929 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Wed, 21 Apr 2021 16:35:52 +0200 Subject: simulator: Migrate to SimulationCoroutineDispatcher This change migrates the remainder of the codebase to the SimulationCoroutineDispatcher implementation. --- .../org/opendc/experiments/serverless/ServerlessExperiment.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'simulator/opendc-experiments/opendc-experiments-serverless20') diff --git a/simulator/opendc-experiments/opendc-experiments-serverless20/src/main/kotlin/org/opendc/experiments/serverless/ServerlessExperiment.kt b/simulator/opendc-experiments/opendc-experiments-serverless20/src/main/kotlin/org/opendc/experiments/serverless/ServerlessExperiment.kt index 5967c2d9..67b5ea54 100644 --- a/simulator/opendc-experiments/opendc-experiments-serverless20/src/main/kotlin/org/opendc/experiments/serverless/ServerlessExperiment.kt +++ b/simulator/opendc-experiments/opendc-experiments-serverless20/src/main/kotlin/org/opendc/experiments/serverless/ServerlessExperiment.kt @@ -28,7 +28,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import kotlinx.coroutines.test.runBlockingTest import mu.KotlinLogging import org.opendc.experiments.serverless.trace.FunctionTraceWorkload import org.opendc.experiments.serverless.trace.ServerlessTraceReader @@ -43,7 +42,7 @@ import org.opendc.simulator.compute.SimMachineModel import org.opendc.simulator.compute.model.MemoryUnit import org.opendc.simulator.compute.model.ProcessingNode import org.opendc.simulator.compute.model.ProcessingUnit -import org.opendc.simulator.core.DelayControllerClockAdapter +import org.opendc.simulator.core.runBlockingSimulation import org.opendc.telemetry.sdk.toOtelClock import java.io.File import java.util.* @@ -80,8 +79,7 @@ public class ServerlessExperiment : Experiment("Serverless") { private val coldStartModel by anyOf(ColdStartModel.LAMBDA, ColdStartModel.AZURE, ColdStartModel.GOOGLE) @OptIn(ExperimentalCoroutinesApi::class) - override fun doRun(repeat: Int): Unit = runBlockingTest { - val clock = DelayControllerClockAdapter(this) + override fun doRun(repeat: Int): Unit = runBlockingSimulation { val meterProvider: MeterProvider = SdkMeterProvider .builder() .setClock(clock.toOtelClock()) -- cgit v1.2.3