summaryrefslogtreecommitdiff
path: root/opendc-faas/opendc-faas-service/src
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-02-18 16:41:48 +0100
committerGitHub <noreply@github.com>2022-02-18 16:41:48 +0100
commit0cba027933e19254573f2488086db3e4660f93d2 (patch)
tree510659fc8c85fc4a7196d1a769ed2dbcfd4ed787 /opendc-faas/opendc-faas-service/src
parentd7c173f0f7b4cb2584a498155519c287abedeae9 (diff)
parentc82b1725cc606769084155d6c4fba982cd320c41 (diff)
merge: Address technical debt in codebase
This pull request removes some of the existing technical debt in the OpenDC codebase. Close #51 ## Implementation Notes :hammer_and_pick: * Add Pacer to pace scheduling cycles. * Rename utils module to common module * Optimize TimerScheduler * Remove opendc-platform module * Disallow duplicate UIDs for SimHost ## Breaking API Changes :warning: * TimerScheduler does not implement `AutoCloseable` anymore.
Diffstat (limited to 'opendc-faas/opendc-faas-service/src')
-rw-r--r--opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/autoscaler/FunctionTerminationPolicyFixed.kt2
-rw-r--r--opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/internal/FaaSServiceImpl.kt21
2 files changed, 8 insertions, 15 deletions
diff --git a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/autoscaler/FunctionTerminationPolicyFixed.kt b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/autoscaler/FunctionTerminationPolicyFixed.kt
index 63dbadc7..d579ad0c 100644
--- a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/autoscaler/FunctionTerminationPolicyFixed.kt
+++ b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/autoscaler/FunctionTerminationPolicyFixed.kt
@@ -22,9 +22,9 @@
package org.opendc.faas.service.autoscaler
+import org.opendc.common.util.TimerScheduler
import org.opendc.faas.service.deployer.FunctionInstance
import org.opendc.faas.service.deployer.FunctionInstanceState
-import org.opendc.utils.TimerScheduler
import java.time.Clock
import java.time.Duration
import kotlin.coroutines.CoroutineContext
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..1526be9d 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
@@ -27,6 +27,7 @@ import io.opentelemetry.api.metrics.MeterProvider
import kotlinx.coroutines.*
import kotlinx.coroutines.intrinsics.startCoroutineCancellable
import mu.KotlinLogging
+import org.opendc.common.util.Pacer
import org.opendc.faas.api.FaaSClient
import org.opendc.faas.api.FaaSFunction
import org.opendc.faas.service.FaaSService
@@ -37,7 +38,6 @@ 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 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()
}
/**