diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-05-03 22:32:32 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-03 22:32:32 +0200 |
| commit | 1ce1210be893e7333dfa09266f6990af87c98dc2 (patch) | |
| tree | 3bfdc735ef39353c6c715399c2d9890ff423d4c4 /opendc-simulator/opendc-simulator-resources/src/jmh | |
| parent | 17ffe995ee06d5755cd3943a5ea14f982884009e (diff) | |
| parent | 80335a49513f3e74228aa1bfb998dd54855f68e2 (diff) | |
simulator: Add support for central resource scheduling (#126)
This pull request adds support for central resource scheduling.
This enables possible optimizations in the future where we can efficiently
schedule resource updates.
* Introduce `SimResourceScheduler` which centralizes the logic for
scheduling resource interrupts.
* Fix benchmarks
* Add generic approach for reporting resource events
* Simplify scheduling logic of resource aggregator.
**Breaking API Changes**
* Classes in `opendc-simulator-resources` now take `SimResourceScheduler` as
opposed to a `CoroutineContext` and `Clock`.
Diffstat (limited to 'opendc-simulator/opendc-simulator-resources/src/jmh')
2 files changed, 33 insertions, 67 deletions
diff --git a/opendc-simulator/opendc-simulator-resources/src/jmh/kotlin/org/opendc/simulator/resources/BenchmarkHelpers.kt b/opendc-simulator/opendc-simulator-resources/src/jmh/kotlin/org/opendc/simulator/resources/BenchmarkHelpers.kt deleted file mode 100644 index 8d2587b1..00000000 --- a/opendc-simulator/opendc-simulator-resources/src/jmh/kotlin/org/opendc/simulator/resources/BenchmarkHelpers.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2021 AtLarge Research - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package org.opendc.simulator.resources - -import org.opendc.simulator.resources.consumer.SimTraceConsumer - -/** - * Helper function to create simple consumer workload. - */ -fun createSimpleConsumer(): SimResourceConsumer { - return SimTraceConsumer( - sequenceOf( - SimTraceConsumer.Fragment(1000, 28.0), - SimTraceConsumer.Fragment(1000, 3500.0), - SimTraceConsumer.Fragment(1000, 0.0), - SimTraceConsumer.Fragment(1000, 183.0), - SimTraceConsumer.Fragment(1000, 400.0), - SimTraceConsumer.Fragment(1000, 100.0), - SimTraceConsumer.Fragment(1000, 3000.0), - SimTraceConsumer.Fragment(1000, 4500.0), - ), - ) -} diff --git a/opendc-simulator/opendc-simulator-resources/src/jmh/kotlin/org/opendc/simulator/resources/SimResourceBenchmarks.kt b/opendc-simulator/opendc-simulator-resources/src/jmh/kotlin/org/opendc/simulator/resources/SimResourceBenchmarks.kt index beda3eaa..cd5f33bd 100644 --- a/opendc-simulator/opendc-simulator-resources/src/jmh/kotlin/org/opendc/simulator/resources/SimResourceBenchmarks.kt +++ b/opendc-simulator/opendc-simulator-resources/src/jmh/kotlin/org/opendc/simulator/resources/SimResourceBenchmarks.kt @@ -26,7 +26,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.launch import org.opendc.simulator.core.SimulationCoroutineScope import org.opendc.simulator.core.runBlockingSimulation -import org.opendc.utils.TimerScheduler +import org.opendc.simulator.resources.consumer.SimTraceConsumer import org.openjdk.jmh.annotations.* import java.util.concurrent.TimeUnit @@ -37,67 +37,76 @@ import java.util.concurrent.TimeUnit @OptIn(ExperimentalCoroutinesApi::class) class SimResourceBenchmarks { private lateinit var scope: SimulationCoroutineScope - private lateinit var scheduler: TimerScheduler<Any> + private lateinit var scheduler: SimResourceScheduler @Setup fun setUp() { scope = SimulationCoroutineScope() - scheduler = TimerScheduler(scope.coroutineContext, scope.clock) + scheduler = SimResourceSchedulerTrampoline(scope.coroutineContext, scope.clock) } @State(Scope.Thread) class Workload { - lateinit var consumers: Array<SimResourceConsumer> + lateinit var trace: Sequence<SimTraceConsumer.Fragment> @Setup fun setUp() { - consumers = Array(3) { createSimpleConsumer() } + trace = sequenceOf( + SimTraceConsumer.Fragment(1000, 28.0), + SimTraceConsumer.Fragment(1000, 3500.0), + SimTraceConsumer.Fragment(1000, 0.0), + SimTraceConsumer.Fragment(1000, 183.0), + SimTraceConsumer.Fragment(1000, 400.0), + SimTraceConsumer.Fragment(1000, 100.0), + SimTraceConsumer.Fragment(1000, 3000.0), + SimTraceConsumer.Fragment(1000, 4500.0), + ) } } @Benchmark fun benchmarkSource(state: Workload) { return scope.runBlockingSimulation { - val provider = SimResourceSource(4200.0, clock, scheduler) - return@runBlockingSimulation provider.consume(state.consumers[0]) + val provider = SimResourceSource(4200.0, scheduler) + return@runBlockingSimulation provider.consume(SimTraceConsumer(state.trace)) } } @Benchmark fun benchmarkForwardOverhead(state: Workload) { return scope.runBlockingSimulation { - val provider = SimResourceSource(4200.0, clock, scheduler) + val provider = SimResourceSource(4200.0, scheduler) val forwarder = SimResourceForwarder() provider.startConsumer(forwarder) - return@runBlockingSimulation forwarder.consume(state.consumers[0]) + return@runBlockingSimulation forwarder.consume(SimTraceConsumer(state.trace)) } } @Benchmark fun benchmarkSwitchMaxMinSingleConsumer(state: Workload) { return scope.runBlockingSimulation { - val switch = SimResourceSwitchMaxMin(clock) + val switch = SimResourceSwitchMaxMin(scheduler) - switch.addInput(SimResourceSource(3000.0, clock, scheduler)) - switch.addInput(SimResourceSource(3000.0, clock, scheduler)) + switch.addInput(SimResourceSource(3000.0, scheduler)) + switch.addInput(SimResourceSource(3000.0, scheduler)) val provider = switch.addOutput(3500.0) - return@runBlockingSimulation provider.consume(state.consumers[0]) + return@runBlockingSimulation provider.consume(SimTraceConsumer(state.trace)) } } @Benchmark fun benchmarkSwitchMaxMinTripleConsumer(state: Workload) { return scope.runBlockingSimulation { - val switch = SimResourceSwitchMaxMin(clock) + val switch = SimResourceSwitchMaxMin(scheduler) - switch.addInput(SimResourceSource(3000.0, clock, scheduler)) - switch.addInput(SimResourceSource(3000.0, clock, scheduler)) + switch.addInput(SimResourceSource(3000.0, scheduler)) + switch.addInput(SimResourceSource(3000.0, scheduler)) repeat(3) { i -> launch { val provider = switch.addOutput(3500.0) - provider.consume(state.consumers[i]) + provider.consume(SimTraceConsumer(state.trace)) } } } @@ -108,11 +117,11 @@ class SimResourceBenchmarks { return scope.runBlockingSimulation { val switch = SimResourceSwitchExclusive() - switch.addInput(SimResourceSource(3000.0, clock, scheduler)) - switch.addInput(SimResourceSource(3000.0, clock, scheduler)) + switch.addInput(SimResourceSource(3000.0, scheduler)) + switch.addInput(SimResourceSource(3000.0, scheduler)) val provider = switch.addOutput(3500.0) - return@runBlockingSimulation provider.consume(state.consumers[0]) + return@runBlockingSimulation provider.consume(SimTraceConsumer(state.trace)) } } @@ -121,13 +130,13 @@ class SimResourceBenchmarks { return scope.runBlockingSimulation { val switch = SimResourceSwitchExclusive() - switch.addInput(SimResourceSource(3000.0, clock, scheduler)) - switch.addInput(SimResourceSource(3000.0, clock, scheduler)) + switch.addInput(SimResourceSource(3000.0, scheduler)) + switch.addInput(SimResourceSource(3000.0, scheduler)) - repeat(2) { i -> + repeat(2) { launch { val provider = switch.addOutput(3500.0) - provider.consume(state.consumers[i]) + provider.consume(SimTraceConsumer(state.trace)) } } } |
