diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-01-11 16:33:15 +0100 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-01-11 16:33:15 +0100 |
| commit | 9dbb7bbcc2202955c715aaa3b28c70641a2fbd5b (patch) | |
| tree | bea8e47037660c88df42e04105e7a0b7f709173a /simulator/opendc-compute | |
| parent | f2028b23e25c8520f25a53771a1b261c4e991bb8 (diff) | |
Add support for hypervisor selection
This change allows users to select the hypervisor scheduler to use when
deploying hypervisors onto bare-metal machines.
Diffstat (limited to 'simulator/opendc-compute')
4 files changed, 27 insertions, 23 deletions
diff --git a/simulator/opendc-compute/opendc-compute-simulator/build.gradle.kts b/simulator/opendc-compute/opendc-compute-simulator/build.gradle.kts index d7570e54..dc93e956 100644 --- a/simulator/opendc-compute/opendc-compute-simulator/build.gradle.kts +++ b/simulator/opendc-compute/opendc-compute-simulator/build.gradle.kts @@ -29,10 +29,10 @@ plugins { dependencies { api(project(":opendc-compute:opendc-compute-core")) + api(project(":opendc-simulator:opendc-simulator-compute")) + api(project(":opendc-simulator:opendc-simulator-failures")) implementation(project(":opendc-utils")) implementation("io.github.microutils:kotlin-logging:1.7.9") - implementation(project(":opendc-simulator:opendc-simulator-compute")) - api(project(":opendc-simulator:opendc-simulator-failures")) testImplementation(project(":opendc-simulator:opendc-simulator-core")) testRuntimeOnly("org.slf4j:slf4j-simple:${Library.SLF4J}") diff --git a/simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimVirtDriver.kt b/simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimVirtDriver.kt index 508720e2..d7a8a8b2 100644 --- a/simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimVirtDriver.kt +++ b/simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimVirtDriver.kt @@ -44,7 +44,7 @@ import java.util.* /** * A [VirtDriver] that is simulates virtual machines on a physical machine using [SimHypervisor]. */ -public class SimVirtDriver(private val coroutineScope: CoroutineScope) : VirtDriver, SimWorkload { +public class SimVirtDriver(private val coroutineScope: CoroutineScope, hypervisor: SimHypervisorProvider) : VirtDriver, SimWorkload { /** * The execution context in which the [VirtDriver] runs. */ @@ -71,7 +71,7 @@ public class SimVirtDriver(private val coroutineScope: CoroutineScope) : VirtDri /** * The hypervisor to run multiple workloads. */ - private val hypervisor = SimFairShareHypervisor( + private val hypervisor = hypervisor.create( object : SimHypervisor.Listener { override fun onSliceFinish( hypervisor: SimHypervisor, @@ -132,7 +132,6 @@ public class SimVirtDriver(private val coroutineScope: CoroutineScope) : VirtDri ) availableMemory -= requiredMemory - val vm = VirtualMachine(server, events, hypervisor.createMachine(flavor.toMachineModel())) vms.add(vm) vmStarted(vm) diff --git a/simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimVirtProvisioningService.kt b/simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimVirtProvisioningService.kt index 6b0021e1..defea888 100644 --- a/simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimVirtProvisioningService.kt +++ b/simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimVirtProvisioningService.kt @@ -40,7 +40,9 @@ import org.opendc.compute.core.virt.service.VirtProvisioningEvent import org.opendc.compute.core.virt.service.VirtProvisioningService import org.opendc.compute.core.virt.service.events.* import org.opendc.compute.simulator.allocation.AllocationPolicy +import org.opendc.simulator.compute.SimHypervisorProvider import org.opendc.trace.core.EventTracer +import org.opendc.utils.TimerScheduler import org.opendc.utils.flow.EventFlow import java.time.Clock import java.util.* @@ -55,7 +57,8 @@ public class SimVirtProvisioningService( private val provisioningService: ProvisioningService, public val allocationPolicy: AllocationPolicy, private val tracer: EventTracer, - private val schedulingQuantum: Long = 300000 // 5 minutes in milliseconds + private val hypervisor: SimHypervisorProvider, + private val schedulingQuantum: Long = 300000, // 5 minutes in milliseconds ) : VirtProvisioningService { /** * The logger instance to use. @@ -75,7 +78,7 @@ public class SimVirtProvisioningService( /** * The incoming images to be processed by the provisioner. */ - private val incomingImages: MutableSet<ImageView> = mutableSetOf() + private val incomingImages: Deque<ImageView> = ArrayDeque() /** * The active images in the system. @@ -103,11 +106,16 @@ public class SimVirtProvisioningService( override val events: Flow<VirtProvisioningEvent> = eventFlow + /** + * The [TimerScheduler] to use for scheduling the scheduler cycles. + */ + private var scheduler: TimerScheduler<Unit> = TimerScheduler(coroutineScope, clock) + init { coroutineScope.launch { val provisionedNodes = provisioningService.nodes() provisionedNodes.forEach { node -> - val workload = SimVirtDriver(coroutineScope) + val workload = SimVirtDriver(coroutineScope, hypervisor) val hypervisorImage = SimWorkloadImage(UUID.randomUUID(), "vmm", emptyMap(), workload) launch { var init = false @@ -169,10 +177,9 @@ public class SimVirtProvisioningService( provisionedNodes.forEach { node -> provisioningService.stop(node) } } - private var call: Job? = null - private fun requestCycle() { - if (call != null) { + // Bail out in case we have already requested a new cycle. + if (scheduler.isTimerActive(Unit)) { return } @@ -181,23 +188,19 @@ public class SimVirtProvisioningService( // We calculate here the delay until the next scheduling slot. val delay = schedulingQuantum - (clock.millis() % schedulingQuantum) - val call = coroutineScope.launch { - delay(delay) - this@SimVirtProvisioningService.call = null - schedule() + scheduler.startSingleTimer(Unit, delay) { + coroutineScope.launch { schedule() } } - this.call = call } private suspend fun schedule() { - val imagesToBeScheduled = incomingImages.toSet() - - for (imageInstance in imagesToBeScheduled) { + while (incomingImages.isNotEmpty()) { + val imageInstance = incomingImages.peekFirst() val requiredMemory = imageInstance.flavor.memorySize val selectedHv = allocationLogic.select(availableHypervisors, imageInstance) if (selectedHv == null || !selectedHv.driver.canFit(imageInstance.flavor)) { - logger.debug { "Server ${imageInstance.server} selected for scheduling but no capacity available for it." } + logger.trace { "Image ${imageInstance.image} selected for scheduling but no capacity available for it." } if (requiredMemory > maxMemory || imageInstance.flavor.cpuCount > maxCores) { tracer.commit(VmSubmissionInvalidEvent(imageInstance.name)) @@ -215,7 +218,8 @@ public class SimVirtProvisioningService( ) ) - incomingImages -= imageInstance + // Remove the incoming image + incomingImages.poll() logger.warn("Failed to spawn ${imageInstance.image}: does not fit [${clock.millis()}]") continue @@ -226,7 +230,7 @@ public class SimVirtProvisioningService( try { logger.info { "[${clock.millis()}] Spawning ${imageInstance.image} on ${selectedHv.server.uid} ${selectedHv.server.name} ${selectedHv.server.flavor}" } - incomingImages -= imageInstance + incomingImages.poll() // Speculatively update the hypervisor view information to prevent other images in the queue from // deciding on stale values. diff --git a/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimVirtDriverTest.kt b/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimVirtDriverTest.kt index 163b326a..1831eae0 100644 --- a/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimVirtDriverTest.kt +++ b/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimVirtDriverTest.kt @@ -34,6 +34,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertAll import org.opendc.compute.core.Flavor import org.opendc.compute.core.virt.HypervisorEvent +import org.opendc.simulator.compute.SimFairShareHypervisorProvider import org.opendc.simulator.compute.SimMachineModel import org.opendc.simulator.compute.model.MemoryUnit import org.opendc.simulator.compute.model.ProcessingNode @@ -75,7 +76,7 @@ internal class SimVirtDriverTest { var overcommittedWork = 0L scope.launch { - val virtDriver = SimVirtDriver(this) + val virtDriver = SimVirtDriver(this, SimFairShareHypervisorProvider()) val vmm = SimWorkloadImage(UUID.randomUUID(), "vmm", emptyMap(), virtDriver) val duration = 5 * 60L val vmImageA = SimWorkloadImage( |
