summaryrefslogtreecommitdiff
path: root/opendc-compute/opendc-compute-simulator/src/test/kotlin
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-05-27 16:34:06 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-06-01 14:48:24 +0200
commit9e5e830e15b74f040708e98c09ea41cd96d13871 (patch)
tree5c2ac6bb2e9a37cc7da36f31092f24c33fb2e15c /opendc-compute/opendc-compute-simulator/src/test/kotlin
parentcd2e3288d28d23556a81bad76dab0aae2e055ac2 (diff)
simulator: Centralize resource logic in SimResourceInterpreter
This change introduces the SimResourceInterpreter which centralizes the logic for scheduling and interpreting the communication between resource consumer and provider. This approach offers better performance due to avoiding invalidating the state of the resource context when not necessary. Benchmarks show in the best case a 5x performance improvement and at worst a 2x improvement.
Diffstat (limited to 'opendc-compute/opendc-compute-simulator/src/test/kotlin')
-rw-r--r--opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt19
1 files changed, 14 insertions, 5 deletions
diff --git a/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt b/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt
index 5594fd59..a6cff3ba 100644
--- a/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt
+++ b/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt
@@ -124,9 +124,18 @@ internal class SimHostTest {
object : MetricExporter {
override fun export(metrics: Collection<MetricData>): CompletableResultCode {
val metricsByName = metrics.associateBy { it.name }
- requestedWork += metricsByName.getValue("cpu.work.total").doubleSummaryData.points.first().sum.toLong()
- grantedWork += metricsByName.getValue("cpu.work.granted").doubleSummaryData.points.first().sum.toLong()
- overcommittedWork += metricsByName.getValue("cpu.work.overcommit").doubleSummaryData.points.first().sum.toLong()
+ val totalWork = metricsByName["cpu.work.total"]
+ if (totalWork != null) {
+ requestedWork += totalWork.doubleSummaryData.points.first().sum.toLong()
+ }
+ val grantedWorkCycle = metricsByName["cpu.work.granted"]
+ if (grantedWorkCycle != null) {
+ grantedWork += grantedWorkCycle.doubleSummaryData.points.first().sum.toLong()
+ }
+ val overcommittedWorkCycle = metricsByName["cpu.work.overcommit"]
+ if (overcommittedWorkCycle != null) {
+ overcommittedWork += overcommittedWorkCycle.doubleSummaryData.points.first().sum.toLong()
+ }
return CompletableResultCode.ofSuccess()
}
@@ -160,8 +169,8 @@ internal class SimHostTest {
reader.close()
assertAll(
- { assertEquals(4197600, requestedWork, "Requested work does not match") },
- { assertEquals(2157600, grantedWork, "Granted work does not match") },
+ { assertEquals(4147200, requestedWork, "Requested work does not match") },
+ { assertEquals(2107200, grantedWork, "Granted work does not match") },
{ assertEquals(2040000, overcommittedWork, "Overcommitted work does not match") },
{ assertEquals(1500001, clock.millis()) }
)