summaryrefslogtreecommitdiff
path: root/opendc-compute
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-compute
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-compute')
-rw-r--r--opendc-compute/opendc-compute-api/build.gradle.kts4
-rw-r--r--opendc-compute/opendc-compute-service/build.gradle.kts3
-rw-r--r--opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ComputeServiceImpl.kt26
-rw-r--r--opendc-compute/opendc-compute-simulator/build.gradle.kts3
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt6
-rw-r--r--opendc-compute/opendc-compute-workload/build.gradle.kts1
-rw-r--r--opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeServiceHelper.kt2
7 files changed, 17 insertions, 28 deletions
diff --git a/opendc-compute/opendc-compute-api/build.gradle.kts b/opendc-compute/opendc-compute-api/build.gradle.kts
index 880ee03d..2ac7e64c 100644
--- a/opendc-compute/opendc-compute-api/build.gradle.kts
+++ b/opendc-compute/opendc-compute-api/build.gradle.kts
@@ -26,7 +26,3 @@ description = "API interface for the OpenDC Compute service"
plugins {
`kotlin-library-conventions`
}
-
-dependencies {
- api(platform(projects.opendcPlatform))
-}
diff --git a/opendc-compute/opendc-compute-service/build.gradle.kts b/opendc-compute/opendc-compute-service/build.gradle.kts
index 33cafc45..b9437a73 100644
--- a/opendc-compute/opendc-compute-service/build.gradle.kts
+++ b/opendc-compute/opendc-compute-service/build.gradle.kts
@@ -30,10 +30,9 @@ plugins {
}
dependencies {
- api(platform(projects.opendcPlatform))
api(projects.opendcCompute.opendcComputeApi)
api(projects.opendcTelemetry.opendcTelemetryApi)
- implementation(projects.opendcUtils)
+ implementation(projects.opendcCommon)
implementation(libs.kotlin.logging)
implementation(libs.opentelemetry.semconv)
diff --git a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ComputeServiceImpl.kt b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ComputeServiceImpl.kt
index 27a6ecae..144b6573 100644
--- a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ComputeServiceImpl.kt
+++ b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ComputeServiceImpl.kt
@@ -29,13 +29,13 @@ import io.opentelemetry.api.metrics.MeterProvider
import io.opentelemetry.api.metrics.ObservableLongMeasurement
import kotlinx.coroutines.*
import mu.KotlinLogging
+import org.opendc.common.util.Pacer
import org.opendc.compute.api.*
import org.opendc.compute.service.ComputeService
import org.opendc.compute.service.driver.Host
import org.opendc.compute.service.driver.HostListener
import org.opendc.compute.service.driver.HostState
import org.opendc.compute.service.scheduler.ComputeScheduler
-import org.opendc.utils.TimerScheduler
import java.time.Clock
import java.time.Duration
import java.util.*
@@ -56,7 +56,7 @@ internal class ComputeServiceImpl(
private val clock: Clock,
meterProvider: MeterProvider,
private val scheduler: ComputeScheduler,
- private val schedulingQuantum: Duration
+ schedulingQuantum: Duration
) : ComputeService, HostListener {
/**
* The [CoroutineScope] of the service bounded by the lifecycle of the service.
@@ -147,9 +147,9 @@ internal class ComputeServiceImpl(
private val _serversActiveAttr = Attributes.of(AttributeKey.stringKey("state"), "active")
/**
- * The [TimerScheduler] to use for scheduling the scheduler cycles.
+ * The [Pacer] to use for scheduling the scheduler cycles.
*/
- private var timerScheduler: TimerScheduler<Unit> = TimerScheduler(scope.coroutineContext, clock)
+ private val pacer = Pacer(scope.coroutineContext, clock, schedulingQuantum.toMillis(), ::doSchedule)
override val hosts: Set<Host>
get() = hostToView.keys
@@ -354,28 +354,18 @@ internal class ComputeServiceImpl(
* 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) || queue.isEmpty()) {
+ // Bail out in case the queue is empty.
+ if (queue.isEmpty()) {
return
}
- val quantum = schedulingQuantum.toMillis()
-
- // 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()
- }
+ pacer.enqueue()
}
/**
* Run a single scheduling iteration.
*/
- private fun doSchedule() {
- val now = clock.millis()
+ private fun doSchedule(now: Long) {
while (queue.isNotEmpty()) {
val request = queue.peek()
diff --git a/opendc-compute/opendc-compute-simulator/build.gradle.kts b/opendc-compute/opendc-compute-simulator/build.gradle.kts
index aaf69f78..9a8cbfcc 100644
--- a/opendc-compute/opendc-compute-simulator/build.gradle.kts
+++ b/opendc-compute/opendc-compute-simulator/build.gradle.kts
@@ -30,11 +30,10 @@ plugins {
}
dependencies {
- api(platform(projects.opendcPlatform))
api(projects.opendcCompute.opendcComputeService)
api(projects.opendcSimulator.opendcSimulatorCompute)
api(libs.commons.math3)
- implementation(projects.opendcUtils)
+ implementation(projects.opendcCommon)
implementation(libs.opentelemetry.semconv)
implementation(libs.kotlin.logging)
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt
index 95921e8b..43f33f27 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt
@@ -249,6 +249,12 @@ public class SimHost(
machine.cancel()
}
+ override fun hashCode(): Int = uid.hashCode()
+
+ override fun equals(other: Any?): Boolean {
+ return other is SimHost && uid == other.uid
+ }
+
override fun toString(): String = "SimHost[uid=$uid,name=$name,model=$model]"
public suspend fun fail() {
diff --git a/opendc-compute/opendc-compute-workload/build.gradle.kts b/opendc-compute/opendc-compute-workload/build.gradle.kts
index 28a5e1da..93e09b99 100644
--- a/opendc-compute/opendc-compute-workload/build.gradle.kts
+++ b/opendc-compute/opendc-compute-workload/build.gradle.kts
@@ -29,7 +29,6 @@ plugins {
}
dependencies {
- api(platform(projects.opendcPlatform))
api(projects.opendcCompute.opendcComputeSimulator)
implementation(projects.opendcTrace.opendcTraceApi)
diff --git a/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeServiceHelper.kt b/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeServiceHelper.kt
index a1a65da3..4b0b343f 100644
--- a/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeServiceHelper.kt
+++ b/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeServiceHelper.kt
@@ -169,7 +169,7 @@ public class ComputeServiceHelper(
optimize = optimize
)
- _hosts.add(host)
+ require(_hosts.add(host)) { "Host with uid ${spec.uid} already exists" }
service.addHost(host)
return host