summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-08-18 12:13:07 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-08-24 11:20:19 +0200
commit484848e2e0bfdaf46f10112e358d3475dbf8e725 (patch)
treee790b94a66f076ca9091e003af777104633520f6
parent31a1f298c71cd3203fdcd57bd39ba8813009dd5b (diff)
fix(simulator): Record overcommit only after deadline
This change fixes an issue with the simulator where it would record overcomitted work if the output was updated before the deadline was reached.
-rw-r--r--opendc-experiments/opendc-experiments-capelin/src/test/kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt2
-rw-r--r--opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimAbstractResourceAggregator.kt4
-rw-r--r--opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimAbstractResourceProvider.kt7
-rw-r--r--opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceDistributorMaxMin.kt7
-rw-r--r--opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceProviderLogic.kt3
-rw-r--r--opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceSource.kt4
-rw-r--r--opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/impl/SimResourceContextImpl.kt5
7 files changed, 19 insertions, 13 deletions
diff --git a/opendc-experiments/opendc-experiments-capelin/src/test/kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt b/opendc-experiments/opendc-experiments-capelin/src/test/kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt
index 00ab9190..3dca1e09 100644
--- a/opendc-experiments/opendc-experiments-capelin/src/test/kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt
+++ b/opendc-experiments/opendc-experiments-capelin/src/test/kotlin/org/opendc/experiments/capelin/CapelinIntegrationTest.kt
@@ -116,7 +116,7 @@ class CapelinIntegrationTest {
{ assertEquals(0, monitorResults.queuedVms, "No VM should not be in the queue") },
{ assertEquals(155252275350, monitor.totalRequestedBurst) { "Incorrect requested burst" } },
{ assertEquals(155086837649, monitor.totalGrantedBurst) { "Incorrect granted burst" } },
- { assertEquals(165488283, monitor.totalOvercommissionedBurst) { "Incorrect overcommitted burst" } },
+ { assertEquals(155088144, monitor.totalOvercommissionedBurst) { "Incorrect overcommitted burst" } },
{ assertEquals(0, monitor.totalInterferedBurst) { "Incorrect interfered burst" } }
)
}
diff --git a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimAbstractResourceAggregator.kt b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimAbstractResourceAggregator.kt
index 8a24b3e7..00648876 100644
--- a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimAbstractResourceAggregator.kt
+++ b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimAbstractResourceAggregator.kt
@@ -112,8 +112,8 @@ public abstract class SimAbstractResourceAggregator(
doFinish()
}
- override fun onUpdate(ctx: SimResourceControllableContext, work: Double) {
- updateCounters(ctx, work)
+ override fun onUpdate(ctx: SimResourceControllableContext, work: Double, willOvercommit: Boolean) {
+ updateCounters(ctx, work, willOvercommit)
}
override fun getConsumedWork(ctx: SimResourceControllableContext, work: Double, speed: Double, duration: Long): Double {
diff --git a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimAbstractResourceProvider.kt b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimAbstractResourceProvider.kt
index 860c50ee..4e8e803a 100644
--- a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimAbstractResourceProvider.kt
+++ b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimAbstractResourceProvider.kt
@@ -87,7 +87,7 @@ public abstract class SimAbstractResourceProvider(
/**
* Update the counters of the resource provider.
*/
- protected fun updateCounters(ctx: SimResourceContext, work: Double) {
+ protected fun updateCounters(ctx: SimResourceContext, work: Double, willOvercommit: Boolean) {
if (work <= 0.0) {
return
}
@@ -96,7 +96,10 @@ public abstract class SimAbstractResourceProvider(
val remainingWork = ctx.remainingWork
counters.demand += work
counters.actual += work - remainingWork
- counters.overcommit += remainingWork
+
+ if (willOvercommit && remainingWork > 0.0) {
+ counters.overcommit += remainingWork
+ }
}
final override fun startConsumer(consumer: SimResourceConsumer) {
diff --git a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceDistributorMaxMin.kt b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceDistributorMaxMin.kt
index 398797cf..6b420911 100644
--- a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceDistributorMaxMin.kt
+++ b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceDistributorMaxMin.kt
@@ -160,7 +160,8 @@ public class SimResourceDistributorMaxMin(
this.totalRequestedWork = totalRequestedWork
this.totalRequestedSpeed = totalRequestedSpeed
- this.totalAllocatedSpeed = capacity - availableSpeed
+ val totalAllocatedSpeed = capacity - availableSpeed
+ this.totalAllocatedSpeed = totalAllocatedSpeed
val totalAllocatedWork = min(
totalRequestedWork,
totalAllocatedSpeed * min((deadline - interpreter.clock.millis()) / 1000.0, duration)
@@ -262,8 +263,8 @@ public class SimResourceDistributorMaxMin(
return Long.MAX_VALUE
}
- override fun onUpdate(ctx: SimResourceControllableContext, work: Double) {
- updateCounters(ctx, work)
+ override fun onUpdate(ctx: SimResourceControllableContext, work: Double, willOvercommit: Boolean) {
+ updateCounters(ctx, work, willOvercommit)
}
override fun onFinish(ctx: SimResourceControllableContext) {
diff --git a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceProviderLogic.kt b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceProviderLogic.kt
index 17045557..2fe1b00f 100644
--- a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceProviderLogic.kt
+++ b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceProviderLogic.kt
@@ -52,8 +52,9 @@ public interface SimResourceProviderLogic {
*
* @param ctx The context in which the provider runs.
* @param work The amount of work that was requested by the resource consumer.
+ * @param willOvercommit A flag to indicate that the remaining work is overcommitted.
*/
- public fun onUpdate(ctx: SimResourceControllableContext, work: Double) {}
+ public fun onUpdate(ctx: SimResourceControllableContext, work: Double, willOvercommit: Boolean) {}
/**
* This method is invoked when the resource consumer has finished.
diff --git a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceSource.kt b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceSource.kt
index 2f70e3cc..2d53198a 100644
--- a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceSource.kt
+++ b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceSource.kt
@@ -51,8 +51,8 @@ public class SimResourceSource(
}
}
- override fun onUpdate(ctx: SimResourceControllableContext, work: Double) {
- updateCounters(ctx, work)
+ override fun onUpdate(ctx: SimResourceControllableContext, work: Double, willOvercommit: Boolean) {
+ updateCounters(ctx, work, willOvercommit)
}
override fun onFinish(ctx: SimResourceControllableContext) {
diff --git a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/impl/SimResourceContextImpl.kt b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/impl/SimResourceContextImpl.kt
index 98fad068..b79998a3 100644
--- a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/impl/SimResourceContextImpl.kt
+++ b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/impl/SimResourceContextImpl.kt
@@ -202,17 +202,18 @@ internal class SimResourceContextImpl(
val isInterrupted = _flag and FLAG_INTERRUPT != 0
val remainingWork = getRemainingWork(timestamp)
val isConsume = _limit > 0.0
+ val reachedDeadline = _deadline <= timestamp
// Update the resource counters only if there is some progress
if (timestamp > _timestamp) {
- logic.onUpdate(this, _work)
+ logic.onUpdate(this, _work, reachedDeadline)
}
// We should only continue processing the next command if:
// 1. The resource consumption was finished.
// 2. The resource capacity cannot satisfy the demand.
// 3. The resource consumer should be interrupted (e.g., someone called .interrupt())
- if ((isConsume && remainingWork == 0.0) || _deadline <= timestamp || isInterrupted) {
+ if ((isConsume && remainingWork == 0.0) || reachedDeadline || isInterrupted) {
when (val command = consumer.onNext(this)) {
is SimResourceCommand.Idle -> interpretIdle(timestamp, command.deadline)
is SimResourceCommand.Consume -> interpretConsume(timestamp, command.work, command.limit, command.deadline)