summaryrefslogtreecommitdiff
path: root/simulator/opendc-simulator/opendc-simulator-compute/src/test
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-01-08 18:18:43 +0100
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-01-11 15:23:56 +0100
commita71d4885efcf01850bc236d3e9f77ab3f44b48aa (patch)
tree797c65e0e5a37b73820ba4ef5d377b4a5524cd5f /simulator/opendc-simulator/opendc-simulator-compute/src/test
parent42e9a5b5b610f41a03e68f6fc781c54b9402925b (diff)
Convert to pull-based workload model
This change converts the low-level workload model to be pull-based. This reduces the overhead that we experienced with our previous co-routine based approach.
Diffstat (limited to 'simulator/opendc-simulator/opendc-simulator-compute/src/test')
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt117
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt88
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimFlopsWorkloadTest.kt22
3 files changed, 175 insertions, 52 deletions
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt
index e7fdd4b2..b8eee4f0 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt
@@ -26,7 +26,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.TestCoroutineScope
import kotlinx.coroutines.yield
-import org.junit.jupiter.api.Assertions
+import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertAll
@@ -51,7 +51,7 @@ internal class SimHypervisorTest {
scope = TestCoroutineScope()
clock = DelayControllerClockAdapter(scope)
- val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 2)
+ val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 1)
machineModel = SimMachineModel(
cpus = List(cpuNode.coreCount) { ProcessingUnit(cpuNode, it, 3200.0) },
memory = List(4) { MemoryUnit("Crucial", "MTA18ASF4G72AZ-3G2B1", 3200.0, 32_000) }
@@ -59,27 +59,27 @@ internal class SimHypervisorTest {
}
/**
- * Test overcommissioning of a hypervisor.
+ * Test overcommitting of resources via the hypervisor with a single VM.
*/
@Test
- fun overcommission() {
+ fun testOvercommittedSingle() {
val listener = object : SimHypervisor.Listener {
- var totalRequestedBurst = 0L
- var totalGrantedBurst = 0L
- var totalOvercommissionedBurst = 0L
+ var totalRequestedWork = 0L
+ var totalGrantedWork = 0L
+ var totalOvercommittedWork = 0L
override fun onSliceFinish(
hypervisor: SimHypervisor,
- requestedBurst: Long,
- grantedBurst: Long,
- overcommissionedBurst: Long,
- interferedBurst: Long,
+ requestedWork: Long,
+ grantedWork: Long,
+ overcommittedWork: Long,
+ interferedWork: Long,
cpuUsage: Double,
cpuDemand: Double
) {
- totalRequestedBurst += requestedBurst
- totalGrantedBurst += grantedBurst
- totalOvercommissionedBurst += overcommissionedBurst
+ totalRequestedWork += requestedWork
+ totalGrantedWork += grantedWork
+ totalOvercommittedWork += overcommittedWork
}
}
@@ -88,24 +88,84 @@ internal class SimHypervisorTest {
val workloadA =
SimTraceWorkload(
sequenceOf(
- SimTraceWorkload.Fragment(0, 28L * duration, duration * 1000, 28.0, 2),
- SimTraceWorkload.Fragment(0, 3500L * duration, duration * 1000, 3500.0, 2),
- SimTraceWorkload.Fragment(0, 0, duration * 1000, 0.0, 2),
- SimTraceWorkload.Fragment(0, 183L * duration, duration * 1000, 183.0, 2)
+ SimTraceWorkload.Fragment(duration * 1000, 28.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 3500.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 0.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 183.0, 1)
+ ),
+ )
+
+ val machine = SimBareMetalMachine(scope, clock, machineModel)
+ val hypervisor = SimFairShareHypervisor(listener)
+
+ launch {
+ machine.run(hypervisor)
+ }
+
+ yield()
+ launch { hypervisor.createMachine(machineModel).run(workloadA) }
+ }
+
+ scope.advanceUntilIdle()
+ scope.uncaughtExceptions.forEach { it.printStackTrace() }
+
+ assertAll(
+ { assertEquals(emptyList<Throwable>(), scope.uncaughtExceptions, "No errors") },
+ { assertEquals(1113300, listener.totalRequestedWork, "Requested Burst does not match") },
+ { assertEquals(1023300, listener.totalGrantedWork, "Granted Burst does not match") },
+ { assertEquals(90000, listener.totalOvercommittedWork, "Overcommissioned Burst does not match") },
+ { assertEquals(1200000, scope.currentTime) }
+ )
+ }
+
+ /**
+ * Test overcommitting of resources via the hypervisor with two VMs.
+ */
+ @Test
+ fun testOvercommittedDual() {
+ val listener = object : SimHypervisor.Listener {
+ var totalRequestedWork = 0L
+ var totalGrantedWork = 0L
+ var totalOvercommittedWork = 0L
+
+ override fun onSliceFinish(
+ hypervisor: SimHypervisor,
+ requestedWork: Long,
+ grantedWork: Long,
+ overcommittedWork: Long,
+ interferedWork: Long,
+ cpuUsage: Double,
+ cpuDemand: Double
+ ) {
+ totalRequestedWork += requestedWork
+ totalGrantedWork += grantedWork
+ totalOvercommittedWork += overcommittedWork
+ }
+ }
+
+ scope.launch {
+ val duration = 5 * 60L
+ val workloadA =
+ SimTraceWorkload(
+ sequenceOf(
+ SimTraceWorkload.Fragment(duration * 1000, 28.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 3500.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 0.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 183.0, 1)
),
)
val workloadB =
SimTraceWorkload(
sequenceOf(
- SimTraceWorkload.Fragment(0, 28L * duration, duration * 1000, 28.0, 2),
- SimTraceWorkload.Fragment(0, 3100L * duration, duration * 1000, 3100.0, 2),
- SimTraceWorkload.Fragment(0, 0, duration * 1000, 0.0, 2),
- SimTraceWorkload.Fragment(0, 73L * duration, duration * 1000, 73.0, 2)
+ SimTraceWorkload.Fragment(duration * 1000, 28.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 3100.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 0.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 73.0, 1)
)
)
val machine = SimBareMetalMachine(scope, clock, machineModel)
- val hypervisor = SimFairSharedHypervisor(scope, clock, listener)
+ val hypervisor = SimFairShareHypervisor(listener)
launch {
machine.run(hypervisor)
@@ -117,13 +177,14 @@ internal class SimHypervisorTest {
}
scope.advanceUntilIdle()
+ scope.uncaughtExceptions.forEach { it.printStackTrace() }
assertAll(
- { Assertions.assertEquals(emptyList<Throwable>(), scope.uncaughtExceptions, "No errors") },
- { Assertions.assertEquals(2082000, listener.totalRequestedBurst, "Requested Burst does not match") },
- { Assertions.assertEquals(2013600, listener.totalGrantedBurst, "Granted Burst does not match") },
- { Assertions.assertEquals(60000, listener.totalOvercommissionedBurst, "Overcommissioned Burst does not match") },
- { Assertions.assertEquals(1200001, scope.currentTime) }
+ { assertEquals(emptyList<Throwable>(), scope.uncaughtExceptions, "No errors") },
+ { assertEquals(2082000, listener.totalRequestedWork, "Requested Burst does not match") },
+ { assertEquals(1062000, listener.totalGrantedWork, "Granted Burst does not match") },
+ { assertEquals(1020000, listener.totalOvercommittedWork, "Overcommissioned Burst does not match") },
+ { assertEquals(1200000, scope.currentTime) }
)
}
}
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
index 332ca8e9..1036f1ac 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
@@ -23,15 +23,20 @@
package org.opendc.simulator.compute
import kotlinx.coroutines.*
+import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.test.TestCoroutineScope
import kotlinx.coroutines.test.runBlockingTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.assertDoesNotThrow
+import org.junit.jupiter.api.assertThrows
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.workload.SimFlopsWorkload
+import org.opendc.simulator.compute.workload.SimResourceCommand
+import org.opendc.simulator.compute.workload.SimWorkload
import org.opendc.simulator.utils.DelayControllerClockAdapter
/**
@@ -58,7 +63,7 @@ class SimMachineTest {
val machine = SimBareMetalMachine(testScope, clock, machineModel)
testScope.runBlockingTest {
- machine.run(SimFlopsWorkload(2_000, 2, utilization = 1.0))
+ machine.run(SimFlopsWorkload(2_000, utilization = 1.0))
// Two cores execute 1000 MFlOps per second (1000 ms)
assertEquals(1000, testScope.currentTime)
@@ -72,12 +77,83 @@ class SimMachineTest {
val machine = SimBareMetalMachine(testScope, clock, machineModel)
testScope.runBlockingTest {
- machine.run(SimFlopsWorkload(2_000, 2, utilization = 1.0))
- assertEquals(1.0, machine.usage.value)
+ val res = mutableListOf<Double>()
+ val job = launch { machine.usage.toList(res) }
- // Wait for the usage to reset
- delay(1)
- assertEquals(0.0, machine.usage.value)
+ machine.run(SimFlopsWorkload(2_000, utilization = 1.0))
+
+ job.cancel()
+ assertEquals(listOf(0.0, 0.5, 1.0, 0.5, 0.0), res) { "Machine is fully utilized" }
+ }
+ }
+
+ @Test
+ fun testInterrupt() {
+ val testScope = TestCoroutineScope()
+ val clock = DelayControllerClockAdapter(testScope)
+ val machine = SimBareMetalMachine(testScope, clock, machineModel)
+
+ val workload = object : SimWorkload {
+ override fun onStart(ctx: SimExecutionContext) {}
+
+ override fun onStart(ctx: SimExecutionContext, cpu: Int): SimResourceCommand {
+ ctx.interrupt(cpu)
+ return SimResourceCommand.Exit
+ }
+
+ override fun onNext(ctx: SimExecutionContext, cpu: Int, remainingWork: Double): SimResourceCommand {
+ throw IllegalStateException()
+ }
+ }
+
+ assertDoesNotThrow {
+ testScope.runBlockingTest { machine.run(workload) }
+ }
+ }
+
+ @Test
+ fun testExceptionPropagationOnStart() {
+ val testScope = TestCoroutineScope()
+ val clock = DelayControllerClockAdapter(testScope)
+ val machine = SimBareMetalMachine(testScope, clock, machineModel)
+
+ val workload = object : SimWorkload {
+ override fun onStart(ctx: SimExecutionContext) {}
+
+ override fun onStart(ctx: SimExecutionContext, cpu: Int): SimResourceCommand {
+ throw IllegalStateException()
+ }
+
+ override fun onNext(ctx: SimExecutionContext, cpu: Int, remainingWork: Double): SimResourceCommand {
+ throw IllegalStateException()
+ }
+ }
+
+ assertThrows<IllegalStateException> {
+ testScope.runBlockingTest { machine.run(workload) }
+ }
+ }
+
+ @Test
+ fun testExceptionPropagationOnNext() {
+ val testScope = TestCoroutineScope()
+ val clock = DelayControllerClockAdapter(testScope)
+ val machine = SimBareMetalMachine(testScope, clock, machineModel)
+
+ val workload = object : SimWorkload {
+ override fun onStart(ctx: SimExecutionContext) {}
+
+ override fun onStart(ctx: SimExecutionContext, cpu: Int): SimResourceCommand {
+ return SimResourceCommand.Consume(1.0, 1.0)
+ }
+
+ override fun onNext(ctx: SimExecutionContext, cpu: Int, remainingWork: Double): SimResourceCommand {
+ throw IllegalStateException()
+ }
+ }
+
+ assertThrows<IllegalStateException> {
+ testScope.runBlockingTest { machine.run(workload) }
}
}
}
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimFlopsWorkloadTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimFlopsWorkloadTest.kt
index 51bed76c..b3e57453 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimFlopsWorkloadTest.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/workload/SimFlopsWorkloadTest.kt
@@ -32,42 +32,28 @@ class SimFlopsWorkloadTest {
@Test
fun testFlopsNonNegative() {
assertThrows<IllegalArgumentException>("FLOPs must be non-negative") {
- SimFlopsWorkload(-1, 1)
- }
- }
-
- @Test
- fun testCoresNonZero() {
- assertThrows<IllegalArgumentException>("Cores cannot be zero") {
- SimFlopsWorkload(1, 0)
- }
- }
-
- @Test
- fun testCoresPositive() {
- assertThrows<IllegalArgumentException>("Cores cannot be negative") {
- SimFlopsWorkload(1, -1)
+ SimFlopsWorkload(-1)
}
}
@Test
fun testUtilizationNonZero() {
assertThrows<IllegalArgumentException>("Utilization cannot be zero") {
- SimFlopsWorkload(1, 1, 0.0)
+ SimFlopsWorkload(1, 0.0)
}
}
@Test
fun testUtilizationPositive() {
assertThrows<IllegalArgumentException>("Utilization cannot be negative") {
- SimFlopsWorkload(1, 1, -1.0)
+ SimFlopsWorkload(1, -1.0)
}
}
@Test
fun testUtilizationNotLargerThanOne() {
assertThrows<IllegalArgumentException>("Utilization cannot be larger than one") {
- SimFlopsWorkload(1, 1, 2.0)
+ SimFlopsWorkload(1, 2.0)
}
}
}