summaryrefslogtreecommitdiff
path: root/simulator/opendc-simulator/opendc-simulator-compute/src/test
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-04-07 21:59:13 +0200
committerGitHub <noreply@github.com>2021-04-07 21:59:13 +0200
commit5d3b759b18fb0a4278b43dea6a9db478b07804a5 (patch)
tree419dedda10f6a1f1865fbee4d1f546dd8876c940 /simulator/opendc-simulator/opendc-simulator-compute/src/test
parent519141f9af525a853b40eb821e70ca209bc104bf (diff)
parent3d707674ddfa96ae5c090a7c918350b0bef9b50f (diff)
simulator: Optimize bottlenecks in resource layer
This pull request addresses several bottlenecks that were present in the `opendc-simulator-resources` layer and `TimerScheduler`. These changes result into a 4x performance improvement for the energy experiments we are currently doing. * The use of `StateFlow` has been removed where possible. Profiling shows that emitting changes to `StateFlow` becomes a bottleneck in a single-thread context. * `SimSpeedConsumerAdapter` is an alternative for obtaining the changes in speed of a resource. **Breaking API Changes** * `SimResourceSource` does not expose `speed` as `StateFlow` anymore. To monitor speed changes, use `SimSpeedConsumerAdapter`. * Power draw in `SimBareMetalMachine` is not exposed as `StateFlow` anymore.
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/cpufreq/DemandScalingGovernorTest.kt2
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PStateScalingDriverTest.kt8
2 files changed, 5 insertions, 5 deletions
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/DemandScalingGovernorTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/DemandScalingGovernorTest.kt
index 19c06126..c02b6285 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/DemandScalingGovernorTest.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/DemandScalingGovernorTest.kt
@@ -35,7 +35,7 @@ internal class DemandScalingGovernorTest {
fun testSetDemandLimit() {
val ctx = mockk<ScalingContext>(relaxUnitFun = true)
- every { ctx.resource.speed.value } returns 2100.0
+ every { ctx.resource.speed } returns 2100.0
val logic = DemandScalingGovernor().createLogic(ctx)
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PStateScalingDriverTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PStateScalingDriverTest.kt
index 5c30bc1f..c6f233a6 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PStateScalingDriverTest.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PStateScalingDriverTest.kt
@@ -59,7 +59,7 @@ internal class PStateScalingDriverTest {
val resource = mockk<SimResourceSource>()
every { cpu.frequency } returns 4100.0
- every { resource.speed.value } returns 1200.0
+ every { resource.speed } returns 1200.0
val driver = PStateScalingDriver(
sortedMapOf(
@@ -84,7 +84,7 @@ internal class PStateScalingDriverTest {
val resource = mockk<SimResourceSource>()
every { cpu.frequency } returns 4100.0
- every { resource.speed.value } returns 1200.0
+ every { resource.speed } returns 1200.0
val driver = PStateScalingDriver(
sortedMapOf(
@@ -125,11 +125,11 @@ internal class PStateScalingDriverTest {
val scalingContext = logic.createContext(cpu, resource)
- every { resource.speed.value } returns 1400.0
+ every { resource.speed } returns 1400.0
scalingContext.setTarget(1400.0)
assertEquals(150.0, logic.computePower())
- every { resource.speed.value } returns 1400.0
+ every { resource.speed } returns 1400.0
scalingContext.setTarget(4000.0)
assertEquals(235.0, logic.computePower())
}