summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-flow/src/jmh
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-10-05 14:44:43 +0200
committerGitHub <noreply@github.com>2022-10-05 14:44:43 +0200
commitc2047d09b27b0c05f5c203509dde524e17d3b729 (patch)
tree3903d8aed5e87850c92e1b2dce8379ea99bdfa6d /opendc-simulator/opendc-simulator-flow/src/jmh
parentec3b5b462c1b8296ba18a3872f56d569fa70e45b (diff)
parentbe176910eb870209576326ffaad8bf21241fccbd (diff)
merge: Extract scheduler from simulation coroutine dispatcher (#106)
This pull request extracts the scheduler from the `SimulationCoroutineDispatcher` into a separate `SimulationScheduler` class which allows users to re-use the scheduler between different coroutine dispatchers. We implement the `SimulationScheduler` in Java, removing the explicit dependency on Kotlin or `kotlinx-coroutines`. The scheduler uses a separate specialized priority queue implementation that eliminates allocation in the hot path of the simulator. ## Implementation Notes :hammer_and_pick: * Add Java-based simulator core * Use SimulationScheduler in coroutine dispatcher * Rename runBlockingSimulation to runSimulation ## External Dependencies :four_leaf_clover: * N/A ## Breaking API Changes :warning: * The Kotlin API for simulation has been moved to `org.opendc.simulator.kotlin`. * `runBlockingSImulation` renamed to `runSimulation`
Diffstat (limited to 'opendc-simulator/opendc-simulator-flow/src/jmh')
-rw-r--r--opendc-simulator/opendc-simulator-flow/src/jmh/kotlin/org/opendc/simulator/flow/FlowBenchmarks.kt22
1 files changed, 11 insertions, 11 deletions
diff --git a/opendc-simulator/opendc-simulator-flow/src/jmh/kotlin/org/opendc/simulator/flow/FlowBenchmarks.kt b/opendc-simulator/opendc-simulator-flow/src/jmh/kotlin/org/opendc/simulator/flow/FlowBenchmarks.kt
index aabd2220..86fbe8e4 100644
--- a/opendc-simulator/opendc-simulator-flow/src/jmh/kotlin/org/opendc/simulator/flow/FlowBenchmarks.kt
+++ b/opendc-simulator/opendc-simulator-flow/src/jmh/kotlin/org/opendc/simulator/flow/FlowBenchmarks.kt
@@ -24,10 +24,10 @@ package org.opendc.simulator.flow
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
-import org.opendc.simulator.core.runBlockingSimulation
import org.opendc.simulator.flow.mux.ForwardingFlowMultiplexer
import org.opendc.simulator.flow.mux.MaxMinFlowMultiplexer
import org.opendc.simulator.flow.source.TraceFlowSource
+import org.opendc.simulator.kotlin.runSimulation
import org.openjdk.jmh.annotations.*
import java.util.concurrent.ThreadLocalRandom
import java.util.concurrent.TimeUnit
@@ -49,27 +49,27 @@ class FlowBenchmarks {
@Benchmark
fun benchmarkSink() {
- return runBlockingSimulation {
+ return runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val provider = FlowSink(engine, 4200.0)
- return@runBlockingSimulation provider.consume(TraceFlowSource(trace))
+ return@runSimulation provider.consume(TraceFlowSource(trace))
}
}
@Benchmark
fun benchmarkForward() {
- return runBlockingSimulation {
+ return runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val provider = FlowSink(engine, 4200.0)
val forwarder = FlowForwarder(engine)
provider.startConsumer(forwarder)
- return@runBlockingSimulation forwarder.consume(TraceFlowSource(trace))
+ return@runSimulation forwarder.consume(TraceFlowSource(trace))
}
}
@Benchmark
fun benchmarkMuxMaxMinSingleSource() {
- return runBlockingSimulation {
+ return runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val switch = MaxMinFlowMultiplexer(engine)
@@ -77,13 +77,13 @@ class FlowBenchmarks {
FlowSink(engine, 3000.0).startConsumer(switch.newOutput())
val provider = switch.newInput()
- return@runBlockingSimulation provider.consume(TraceFlowSource(trace))
+ return@runSimulation provider.consume(TraceFlowSource(trace))
}
}
@Benchmark
fun benchmarkMuxMaxMinTripleSource() {
- return runBlockingSimulation {
+ return runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val switch = MaxMinFlowMultiplexer(engine)
@@ -101,7 +101,7 @@ class FlowBenchmarks {
@Benchmark
fun benchmarkMuxExclusiveSingleSource() {
- return runBlockingSimulation {
+ return runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val switch = ForwardingFlowMultiplexer(engine)
@@ -109,13 +109,13 @@ class FlowBenchmarks {
FlowSink(engine, 3000.0).startConsumer(switch.newOutput())
val provider = switch.newInput()
- return@runBlockingSimulation provider.consume(TraceFlowSource(trace))
+ return@runSimulation provider.consume(TraceFlowSource(trace))
}
}
@Benchmark
fun benchmarkMuxExclusiveTripleSource() {
- return runBlockingSimulation {
+ return runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val switch = ForwardingFlowMultiplexer(engine)