summaryrefslogtreecommitdiff
path: root/opendc-workflow/opendc-workflow-service/src
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-02-18 12:35:11 +0100
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-02-18 14:46:16 +0100
commit028960fbf584c903156c713447194df56ec5059e (patch)
tree5526a7d82e800263df4d6176e985f4634475c379 /opendc-workflow/opendc-workflow-service/src
parentd7c173f0f7b4cb2584a498155519c287abedeae9 (diff)
feat(utils): Add Pacer to pace scheduling cycles
This change adds a new Pacer class that can pace the incoming scheduling requests into scheduling cycles by allowing the user to specify a scheduling quantum.
Diffstat (limited to 'opendc-workflow/opendc-workflow-service/src')
-rw-r--r--opendc-workflow/opendc-workflow-service/src/main/kotlin/org/opendc/workflow/service/internal/WorkflowServiceImpl.kt38
1 files changed, 6 insertions, 32 deletions
diff --git a/opendc-workflow/opendc-workflow-service/src/main/kotlin/org/opendc/workflow/service/internal/WorkflowServiceImpl.kt b/opendc-workflow/opendc-workflow-service/src/main/kotlin/org/opendc/workflow/service/internal/WorkflowServiceImpl.kt
index 7b6d8651..cb4bfd45 100644
--- a/opendc-workflow/opendc-workflow-service/src/main/kotlin/org/opendc/workflow/service/internal/WorkflowServiceImpl.kt
+++ b/opendc-workflow/opendc-workflow-service/src/main/kotlin/org/opendc/workflow/service/internal/WorkflowServiceImpl.kt
@@ -26,7 +26,7 @@ import io.opentelemetry.api.metrics.Meter
import io.opentelemetry.api.metrics.MeterProvider
import kotlinx.coroutines.*
import org.opendc.compute.api.*
-import org.opendc.utils.TimerScheduler
+import org.opendc.utils.Pacer
import org.opendc.workflow.api.Job
import org.opendc.workflow.api.WORKFLOW_TASK_CORES
import org.opendc.workflow.service.*
@@ -187,9 +187,9 @@ public class WorkflowServiceImpl(
.build()
/**
- * The [TimerScheduler] to use for scheduling the scheduler cycles.
+ * The [Pacer] to use for scheduling the scheduler cycles.
*/
- private val timerScheduler: TimerScheduler<Unit> = TimerScheduler(scope.coroutineContext, clock)
+ private val pacer = Pacer(scope.coroutineContext, clock, schedulingQuantum.toMillis()) { doSchedule() }
private val jobAdmissionPolicy: JobAdmissionPolicy.Logic
private val taskEligibilityPolicy: TaskEligibilityPolicy.Logic
@@ -230,7 +230,7 @@ public class WorkflowServiceImpl(
rootListener.jobSubmitted(jobInstance)
submittedJobs.add(1)
- requestSchedulingCycle()
+ pacer.enqueue()
}
override fun close() {
@@ -252,31 +252,6 @@ public class WorkflowServiceImpl(
}
/**
- * Indicate that a new scheduling cycle is needed due to a change to the service's state.
- */
- private fun requestSchedulingCycle() {
- // Bail out in case we have already requested a new cycle or the queue is empty.
- if (timerScheduler.isTimerActive(Unit)) {
- return
- }
-
- val quantum = schedulingQuantum.toMillis()
- if (quantum == 0L) {
- doSchedule()
- return
- }
-
- // We assume that the provisioner runs at a fixed slot every time quantum (e.g t=0, t=60, t=120).
- // This is important because the slices of the VMs need to be aligned.
- // We calculate here the delay until the next scheduling slot.
- val delay = quantum - (clock.millis() % quantum)
-
- timerScheduler.startSingleTimer(Unit, delay) {
- doSchedule()
- }
- }
-
- /**
* Perform a scheduling cycle immediately.
*/
private fun doSchedule() {
@@ -409,10 +384,9 @@ public class WorkflowServiceImpl(
finishJob(job)
}
- requestSchedulingCycle()
- }
- ServerState.DELETED -> {
+ pacer.enqueue()
}
+ ServerState.DELETED -> {}
else -> throw IllegalStateException()
}
}