diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-04-21 14:30:55 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-04-21 16:37:18 +0200 |
| commit | 1c0568c31d60d4e690b4b9aec2e14f660b72a5c8 (patch) | |
| tree | 20ac429b9a5af131a7272978ca92674b84f37dcb /simulator/opendc-experiments | |
| parent | 59960c92dc7e059e386347b29927fc49d0392b84 (diff) | |
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.
Diffstat (limited to 'simulator/opendc-experiments')
4 files changed, 6 insertions, 11 deletions
diff --git a/simulator/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/Portfolio.kt b/simulator/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/Portfolio.kt index 941d3c97..ee048cb0 100644 --- a/simulator/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/Portfolio.kt +++ b/simulator/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/Portfolio.kt @@ -45,7 +45,7 @@ import org.opendc.format.environment.sc20.Sc20ClusterEnvironmentReader import org.opendc.format.trace.PerformanceInterferenceModelReader import org.opendc.harness.dsl.Experiment import org.opendc.harness.dsl.anyOf -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.* diff --git a/simulator/opendc-experiments/opendc-experiments-capelin/src/test/kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt b/simulator/opendc-experiments/opendc-experiments-capelin/src/test/kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt index 4a47922d..4cb50ab9 100644 --- a/simulator/opendc-experiments/opendc-experiments-capelin/src/test/kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt +++ b/simulator/opendc-experiments/opendc-experiments-capelin/src/test/kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt @@ -25,10 +25,8 @@ package org.opendc.experiments.capelin import io.opentelemetry.api.metrics.MeterProvider import io.opentelemetry.sdk.metrics.SdkMeterProvider import io.opentelemetry.sdk.metrics.export.MetricProducer -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.cancel import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.test.runBlockingTest import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -46,14 +44,13 @@ import org.opendc.format.environment.EnvironmentReader import org.opendc.format.environment.sc20.Sc20ClusterEnvironmentReader import org.opendc.format.trace.TraceReader import org.opendc.simulator.compute.workload.SimWorkload -import org.opendc.simulator.utils.DelayControllerClockAdapter +import org.opendc.simulator.core.runBlockingSimulation import org.opendc.telemetry.sdk.toOtelClock import java.io.File /** * An integration test suite for the SC20 experiments. */ -@OptIn(ExperimentalCoroutinesApi::class) class CapelinIntegrationTest { /** * The monitor used to keep track of the metrics. @@ -69,8 +66,7 @@ class CapelinIntegrationTest { } @Test - fun testLarge() = runBlockingTest { - val clock = DelayControllerClockAdapter(this) + fun testLarge() = runBlockingSimulation { val failures = false val seed = 0 val chan = Channel<Unit>(Channel.CONFLATED) @@ -132,8 +128,7 @@ class CapelinIntegrationTest { } @Test - fun testSmall() = runBlockingTest { - val clock = DelayControllerClockAdapter(this) + fun testSmall() = runBlockingSimulation { val seed = 1 val chan = Channel<Unit>(Channel.CONFLATED) val allocationPolicy = FilterScheduler( diff --git a/simulator/opendc-experiments/opendc-experiments-energy21/src/main/kotlin/org/opendc/experiments/energy21/EnergyExperiment.kt b/simulator/opendc-experiments/opendc-experiments-energy21/src/main/kotlin/org/opendc/experiments/energy21/EnergyExperiment.kt index fc03e1ef..e687ad92 100644 --- a/simulator/opendc-experiments/opendc-experiments-energy21/src/main/kotlin/org/opendc/experiments/energy21/EnergyExperiment.kt +++ b/simulator/opendc-experiments/opendc-experiments-energy21/src/main/kotlin/org/opendc/experiments/energy21/EnergyExperiment.kt @@ -50,7 +50,7 @@ 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.compute.power.* -import org.opendc.simulator.utils.DelayControllerClockAdapter +import org.opendc.simulator.core.DelayControllerClockAdapter import org.opendc.telemetry.sdk.toOtelClock import java.io.File import java.time.Clock 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.* |
