diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-02-18 12:35:11 +0100 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-02-18 14:46:16 +0100 |
| commit | 028960fbf584c903156c713447194df56ec5059e (patch) | |
| tree | 5526a7d82e800263df4d6176e985f4634475c379 /opendc-faas/opendc-faas-service | |
| parent | d7c173f0f7b4cb2584a498155519c287abedeae9 (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-faas/opendc-faas-service')
| -rw-r--r-- | opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/internal/FaaSServiceImpl.kt | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/internal/FaaSServiceImpl.kt b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/internal/FaaSServiceImpl.kt index c285585a..82032718 100644 --- a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/internal/FaaSServiceImpl.kt +++ b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/internal/FaaSServiceImpl.kt @@ -37,7 +37,7 @@ import org.opendc.faas.service.deployer.FunctionInstance import org.opendc.faas.service.deployer.FunctionInstanceListener import org.opendc.faas.service.deployer.FunctionInstanceState import org.opendc.faas.service.router.RoutingPolicy -import org.opendc.utils.TimerScheduler +import org.opendc.utils.Pacer import java.lang.IllegalStateException import java.time.Clock import java.util.* @@ -55,7 +55,7 @@ import kotlin.coroutines.resumeWithException internal class FaaSServiceImpl( context: CoroutineContext, private val clock: Clock, - private val meterProvider: MeterProvider, + meterProvider: MeterProvider, private val deployer: FunctionDeployer, private val routingPolicy: RoutingPolicy, private val terminationPolicy: FunctionTerminationPolicy @@ -76,9 +76,9 @@ internal class FaaSServiceImpl( private val meter = meterProvider.get("org.opendc.faas.service") /** - * The [TimerScheduler] to use for scheduling the scheduler cycles. + * The [Pacer] to use for scheduling the scheduler cycles. */ - private val scheduler: TimerScheduler<Unit> = TimerScheduler(scope.coroutineContext, clock) + private val pacer = Pacer(scope.coroutineContext, clock, quantum = 100) { doSchedule() } /** * The [Random] instance used to generate unique identifiers for the objects. @@ -191,19 +191,12 @@ internal class FaaSServiceImpl( * Indicate that a new scheduling cycle is needed due to a change to the service's state. */ private fun schedule() { - // Bail out in case we have already requested a new cycle or the queue is empty. - if (scheduler.isTimerActive(Unit) || queue.isEmpty()) { + // Bail out in case the queue is empty. + if (queue.isEmpty()) { return } - val quantum = 100 - - // 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) - - scheduler.startSingleTimer(Unit, delay, ::doSchedule) + pacer.enqueue() } /** |
