summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-compute/src/test
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-compute/src/test
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-compute/src/test')
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt24
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/device/SimPsuTest.kt6
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisorTest.kt10
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt14
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkloadTest.kt10
5 files changed, 32 insertions, 32 deletions
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
index 644eb497..b7af6803 100644
--- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
@@ -33,9 +33,9 @@ import org.opendc.simulator.compute.power.SimplePowerDriver
import org.opendc.simulator.compute.workload.SimFlopsWorkload
import org.opendc.simulator.compute.workload.SimWorkload
import org.opendc.simulator.compute.workload.SimWorkloadLifecycle
-import org.opendc.simulator.core.runBlockingSimulation
import org.opendc.simulator.flow.FlowEngine
import org.opendc.simulator.flow.source.FixedFlowSource
+import org.opendc.simulator.kotlin.runSimulation
import org.opendc.simulator.network.SimNetworkSink
import org.opendc.simulator.power.SimPowerSource
@@ -58,7 +58,7 @@ class SimMachineTest {
}
@Test
- fun testFlopsWorkload() = runBlockingSimulation {
+ fun testFlopsWorkload() = runSimulation {
val machine = SimBareMetalMachine(
FlowEngine(coroutineContext, clock),
machineModel,
@@ -72,7 +72,7 @@ class SimMachineTest {
}
@Test
- fun testDualSocketMachine() = runBlockingSimulation {
+ fun testDualSocketMachine() = runSimulation {
val cpuNode = machineModel.cpus[0].node
val machineModel = MachineModel(
cpus = List(cpuNode.coreCount * 2) { ProcessingUnit(cpuNode, it % 2, 1000.0) },
@@ -91,7 +91,7 @@ class SimMachineTest {
}
@Test
- fun testPower() = runBlockingSimulation {
+ fun testPower() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val machine = SimBareMetalMachine(
engine,
@@ -111,7 +111,7 @@ class SimMachineTest {
}
@Test
- fun testCapacityClamp() = runBlockingSimulation {
+ fun testCapacityClamp() = runSimulation {
val machine = SimBareMetalMachine(
FlowEngine(coroutineContext, clock),
machineModel,
@@ -135,7 +135,7 @@ class SimMachineTest {
}
@Test
- fun testMemory() = runBlockingSimulation {
+ fun testMemory() = runSimulation {
val machine = SimBareMetalMachine(
FlowEngine(coroutineContext, clock),
machineModel,
@@ -153,7 +153,7 @@ class SimMachineTest {
}
@Test
- fun testMemoryUsage() = runBlockingSimulation {
+ fun testMemoryUsage() = runSimulation {
val machine = SimBareMetalMachine(
FlowEngine(coroutineContext, clock),
machineModel,
@@ -173,7 +173,7 @@ class SimMachineTest {
}
@Test
- fun testNetUsage() = runBlockingSimulation {
+ fun testNetUsage() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val machine = SimBareMetalMachine(
engine,
@@ -198,7 +198,7 @@ class SimMachineTest {
}
@Test
- fun testDiskReadUsage() = runBlockingSimulation {
+ fun testDiskReadUsage() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val machine = SimBareMetalMachine(
engine,
@@ -220,7 +220,7 @@ class SimMachineTest {
}
@Test
- fun testDiskWriteUsage() = runBlockingSimulation {
+ fun testDiskWriteUsage() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val machine = SimBareMetalMachine(
engine,
@@ -242,7 +242,7 @@ class SimMachineTest {
}
@Test
- fun testCancellation() = runBlockingSimulation {
+ fun testCancellation() = runSimulation {
val machine = SimBareMetalMachine(
FlowEngine(coroutineContext, clock),
machineModel,
@@ -262,7 +262,7 @@ class SimMachineTest {
}
@Test
- fun testConcurrentRuns() = runBlockingSimulation {
+ fun testConcurrentRuns() = runSimulation {
val machine = SimBareMetalMachine(
FlowEngine(coroutineContext, clock),
machineModel,
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/device/SimPsuTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/device/SimPsuTest.kt
index e5b509f0..5481cad2 100644
--- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/device/SimPsuTest.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/device/SimPsuTest.kt
@@ -28,8 +28,8 @@ import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.opendc.simulator.compute.power.PowerDriver
-import org.opendc.simulator.core.runBlockingSimulation
import org.opendc.simulator.flow.FlowEngine
+import org.opendc.simulator.kotlin.runSimulation
import org.opendc.simulator.power.SimPowerSource
/**
@@ -51,7 +51,7 @@ internal class SimPsuTest {
}
@Test
- fun testPsuIdle() = runBlockingSimulation {
+ fun testPsuIdle() = runSimulation {
val ratedOutputPower = 240.0
val energyEfficiency = mapOf(0.0 to 1.0)
@@ -69,7 +69,7 @@ internal class SimPsuTest {
}
@Test
- fun testPsuPowerLoss() = runBlockingSimulation {
+ fun testPsuPowerLoss() = runSimulation {
val ratedOutputPower = 240.0
// Efficiency of 80 Plus Titanium PSU
val energyEfficiency = sortedMapOf(
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisorTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisorTest.kt
index ddf8cf14..aae8d139 100644
--- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisorTest.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisorTest.kt
@@ -41,9 +41,9 @@ import org.opendc.simulator.compute.runWorkload
import org.opendc.simulator.compute.workload.SimTrace
import org.opendc.simulator.compute.workload.SimTraceFragment
import org.opendc.simulator.compute.workload.SimTraceWorkload
-import org.opendc.simulator.core.runBlockingSimulation
import org.opendc.simulator.flow.FlowEngine
import org.opendc.simulator.flow.mux.FlowMultiplexerFactory
+import org.opendc.simulator.kotlin.runSimulation
import java.util.*
/**
@@ -65,7 +65,7 @@ internal class SimFairShareHypervisorTest {
* Test overcommitting of resources via the hypervisor with a single VM.
*/
@Test
- fun testOvercommittedSingle() = runBlockingSimulation {
+ fun testOvercommittedSingle() = runSimulation {
val duration = 5 * 60L
val workloadA =
SimTraceWorkload(
@@ -105,7 +105,7 @@ internal class SimFairShareHypervisorTest {
* Test overcommitting of resources via the hypervisor with two VMs.
*/
@Test
- fun testOvercommittedDual() = runBlockingSimulation {
+ fun testOvercommittedDual() = runSimulation {
val duration = 5 * 60L
val workloadA =
SimTraceWorkload(
@@ -158,7 +158,7 @@ internal class SimFairShareHypervisorTest {
}
@Test
- fun testMultipleCPUs() = runBlockingSimulation {
+ fun testMultipleCPUs() = runSimulation {
val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 2)
val model = MachineModel(
cpus = List(cpuNode.coreCount) { ProcessingUnit(cpuNode, it, 3200.0) },
@@ -179,7 +179,7 @@ internal class SimFairShareHypervisorTest {
}
@Test
- fun testInterference() = runBlockingSimulation {
+ fun testInterference() = runSimulation {
val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 2)
val model = MachineModel(
cpus = List(cpuNode.coreCount) { ProcessingUnit(cpuNode, it, 3200.0) },
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt
index df6755f1..664bb2da 100644
--- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt
@@ -37,9 +37,9 @@ import org.opendc.simulator.compute.power.ConstantPowerModel
import org.opendc.simulator.compute.power.SimplePowerDriver
import org.opendc.simulator.compute.runWorkload
import org.opendc.simulator.compute.workload.*
-import org.opendc.simulator.core.runBlockingSimulation
import org.opendc.simulator.flow.FlowEngine
import org.opendc.simulator.flow.mux.FlowMultiplexerFactory
+import org.opendc.simulator.kotlin.runSimulation
import java.util.*
/**
@@ -61,7 +61,7 @@ internal class SimSpaceSharedHypervisorTest {
* Test a trace workload.
*/
@Test
- fun testTrace() = runBlockingSimulation {
+ fun testTrace() = runSimulation {
val duration = 5 * 60L
val workloadA =
SimTraceWorkload(
@@ -92,7 +92,7 @@ internal class SimSpaceSharedHypervisorTest {
* Test runtime workload on hypervisor.
*/
@Test
- fun testRuntimeWorkload() = runBlockingSimulation {
+ fun testRuntimeWorkload() = runSimulation {
val duration = 5 * 60L * 1000
val workload = SimRuntimeWorkload(duration)
val engine = FlowEngine(coroutineContext, clock)
@@ -114,7 +114,7 @@ internal class SimSpaceSharedHypervisorTest {
* Test FLOPs workload on hypervisor.
*/
@Test
- fun testFlopsWorkload() = runBlockingSimulation {
+ fun testFlopsWorkload() = runSimulation {
val duration = 5 * 60L * 1000
val workload = SimFlopsWorkload((duration * 3.2).toLong(), 1.0)
val engine = FlowEngine(coroutineContext, clock)
@@ -134,7 +134,7 @@ internal class SimSpaceSharedHypervisorTest {
* Test two workloads running sequentially.
*/
@Test
- fun testTwoWorkloads() = runBlockingSimulation {
+ fun testTwoWorkloads() = runSimulation {
val duration = 5 * 60L * 1000
val engine = FlowEngine(coroutineContext, clock)
val machine = SimBareMetalMachine(engine, machineModel, SimplePowerDriver(ConstantPowerModel(0.0)))
@@ -162,7 +162,7 @@ internal class SimSpaceSharedHypervisorTest {
* Test concurrent workloads on the machine.
*/
@Test
- fun testConcurrentWorkloadFails() = runBlockingSimulation {
+ fun testConcurrentWorkloadFails() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val machine = SimBareMetalMachine(engine, machineModel, SimplePowerDriver(ConstantPowerModel(0.0)))
val hypervisor = SimHypervisor(engine, FlowMultiplexerFactory.forwardingMultiplexer(), SplittableRandom(1), null)
@@ -184,7 +184,7 @@ internal class SimSpaceSharedHypervisorTest {
* Test concurrent workloads on the machine.
*/
@Test
- fun testConcurrentWorkloadSucceeds() = runBlockingSimulation {
+ fun testConcurrentWorkloadSucceeds() = runSimulation {
val engine = FlowEngine(coroutineContext, clock)
val machine = SimBareMetalMachine(engine, machineModel, SimplePowerDriver(ConstantPowerModel(0.0)))
val hypervisor = SimHypervisor(engine, FlowMultiplexerFactory.forwardingMultiplexer(), SplittableRandom(1), null)
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkloadTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkloadTest.kt
index aa91984a..70aea3f4 100644
--- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkloadTest.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkloadTest.kt
@@ -31,8 +31,8 @@ import org.opendc.simulator.compute.model.*
import org.opendc.simulator.compute.power.ConstantPowerModel
import org.opendc.simulator.compute.power.SimplePowerDriver
import org.opendc.simulator.compute.runWorkload
-import org.opendc.simulator.core.runBlockingSimulation
import org.opendc.simulator.flow.FlowEngine
+import org.opendc.simulator.kotlin.runSimulation
/**
* Test suite for the [SimTraceWorkloadTest] class.
@@ -51,7 +51,7 @@ class SimTraceWorkloadTest {
}
@Test
- fun testSmoke() = runBlockingSimulation {
+ fun testSmoke() = runSimulation {
val machine = SimBareMetalMachine(
FlowEngine(coroutineContext, clock),
machineModel,
@@ -74,7 +74,7 @@ class SimTraceWorkloadTest {
}
@Test
- fun testOffset() = runBlockingSimulation {
+ fun testOffset() = runSimulation {
val machine = SimBareMetalMachine(
FlowEngine(coroutineContext, clock),
machineModel,
@@ -97,7 +97,7 @@ class SimTraceWorkloadTest {
}
@Test
- fun testSkipFragment() = runBlockingSimulation {
+ fun testSkipFragment() = runSimulation {
val machine = SimBareMetalMachine(
FlowEngine(coroutineContext, clock),
machineModel,
@@ -121,7 +121,7 @@ class SimTraceWorkloadTest {
}
@Test
- fun testZeroCores() = runBlockingSimulation {
+ fun testZeroCores() = runSimulation {
val machine = SimBareMetalMachine(
FlowEngine(coroutineContext, clock),
machineModel,