diff options
Diffstat (limited to 'opendc')
8 files changed, 62 insertions, 8 deletions
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/VirtDriver.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/VirtDriver.kt index 68b8e541..e68dd488 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/VirtDriver.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/VirtDriver.kt @@ -24,8 +24,8 @@ package com.atlarge.opendc.compute.virt.driver -import com.atlarge.opendc.compute.core.Server import com.atlarge.opendc.compute.core.Flavor +import com.atlarge.opendc.compute.core.Server import com.atlarge.opendc.compute.core.image.Image import com.atlarge.opendc.compute.core.monitor.ServerMonitor import com.atlarge.opendc.core.services.AbstractServiceKey @@ -53,5 +53,12 @@ public interface VirtDriver { */ public suspend fun getNumberOfSpawnedImages(): Int + /** + * Returns the available memory on the server managed by this driver. + * + * @return The available memory, in MB. + */ + public suspend fun getAvailableMemory(): Long + companion object Key : AbstractServiceKey<VirtDriver>(UUID.randomUUID(), "virtual-driver") } diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorVirtDriver.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorVirtDriver.kt index 9745b56c..4b23159f 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorVirtDriver.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorVirtDriver.kt @@ -69,10 +69,6 @@ class HypervisorVirtDriver( return server } - override suspend fun getNumberOfSpawnedImages(): Int { - return vms.size - } - internal inner class VmServerContext( override var server: Server, val monitor: ServerMonitor, diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/SimpleVirtProvisioningService.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/SimpleVirtProvisioningService.kt index 888364e2..309cfa83 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/SimpleVirtProvisioningService.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/SimpleVirtProvisioningService.kt @@ -12,9 +12,11 @@ import com.atlarge.opendc.compute.virt.driver.VirtDriver import com.atlarge.opendc.compute.virt.driver.hypervisor.HypervisorImage import com.atlarge.opendc.compute.virt.driver.hypervisor.InsufficientMemoryOnServerException import com.atlarge.opendc.compute.virt.monitor.HypervisorMonitor +import com.atlarge.opendc.compute.virt.service.allocation.AllocationPolicy import kotlinx.coroutines.launch class SimpleVirtProvisioningService( + public override val allocationPolicy: AllocationPolicy, private val ctx: SimulationContext, private val provisioningService: ProvisioningService, private val hypervisorMonitor: HypervisorMonitor @@ -83,9 +85,7 @@ class SimpleVirtProvisioningService( for (imageInstance in imagesToBeScheduled) { println("Spawning $imageInstance") - val selectedNode = availableNodes.minBy { - it.server!!.serviceRegistry[VirtDriver.Key].getNumberOfSpawnedImages() - } + val selectedNode = availableNodes.minWith(allocationPolicy().thenBy { it.uid }) try { imageInstance.server = selectedNode?.server!!.serviceRegistry[VirtDriver.Key].spawn( diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/VirtProvisioningService.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/VirtProvisioningService.kt index fb087f9d..7770ec50 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/VirtProvisioningService.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/VirtProvisioningService.kt @@ -3,11 +3,14 @@ package com.atlarge.opendc.compute.virt.service import com.atlarge.opendc.compute.core.Flavor import com.atlarge.opendc.compute.core.image.Image import com.atlarge.opendc.compute.core.monitor.ServerMonitor +import com.atlarge.opendc.compute.virt.service.allocation.AllocationPolicy /** * A service for VM provisioning on a cloud. */ interface VirtProvisioningService { + val allocationPolicy: AllocationPolicy + /** * Submit the specified [Image] to the provisioning service. * diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/AllocationPolicy.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/AllocationPolicy.kt new file mode 100644 index 00000000..fc08aa87 --- /dev/null +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/AllocationPolicy.kt @@ -0,0 +1,13 @@ +package com.atlarge.opendc.compute.virt.service.allocation + +import com.atlarge.opendc.compute.metal.Node + +/** + * A policy for selecting the [Node] an image should be deployed to, + */ +interface AllocationPolicy { + /** + * Builds the logic of the policy. + */ + suspend operator fun invoke(): Comparator<Node> +} diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/AvailableMemoryAllocationPolicy.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/AvailableMemoryAllocationPolicy.kt new file mode 100644 index 00000000..e02e2cef --- /dev/null +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/AvailableMemoryAllocationPolicy.kt @@ -0,0 +1,18 @@ +package com.atlarge.opendc.compute.virt.service.allocation + +import com.atlarge.opendc.compute.metal.Node +import com.atlarge.opendc.compute.virt.driver.VirtDriver +import kotlinx.coroutines.runBlocking + +/** + * Allocation policy that selects the node with the most available memory. + */ +class AvailableMemoryAllocationPolicy : AllocationPolicy { + override suspend fun invoke(): Comparator<Node> = Comparator { o1, o2 -> + runBlocking { + compareValuesBy(o1, o2) { + -it.server!!.serviceRegistry[VirtDriver.Key].getAvailableMemory() + } + } + } +} diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/NumHostsAllocationPolicy.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/NumHostsAllocationPolicy.kt new file mode 100644 index 00000000..c5ee29c5 --- /dev/null +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/service/allocation/NumHostsAllocationPolicy.kt @@ -0,0 +1,15 @@ +package com.atlarge.opendc.compute.virt.service.allocation + +import com.atlarge.opendc.compute.metal.Node +import com.atlarge.opendc.compute.virt.driver.VirtDriver +import kotlinx.coroutines.runBlocking + +class NumHostsAllocationPolicy : AllocationPolicy { + override suspend fun invoke(): Comparator<Node> = Comparator { o1, o2 -> + runBlocking { + compareValuesBy(o1, o2) { + it.server!!.serviceRegistry[VirtDriver.Key].getNumberOfSpawnedImages() + } + } + } +} diff --git a/opendc/opendc-experiments-sc20/src/main/kotlin/com/atlarge/opendc/experiments/sc20/TestExperiment.kt b/opendc/opendc-experiments-sc20/src/main/kotlin/com/atlarge/opendc/experiments/sc20/TestExperiment.kt index 48aca303..daa40193 100644 --- a/opendc/opendc-experiments-sc20/src/main/kotlin/com/atlarge/opendc/experiments/sc20/TestExperiment.kt +++ b/opendc/opendc-experiments-sc20/src/main/kotlin/com/atlarge/opendc/experiments/sc20/TestExperiment.kt @@ -32,6 +32,7 @@ import com.atlarge.opendc.compute.core.ServerState import com.atlarge.opendc.compute.core.monitor.ServerMonitor import com.atlarge.opendc.compute.metal.service.ProvisioningService import com.atlarge.opendc.compute.virt.service.SimpleVirtProvisioningService +import com.atlarge.opendc.compute.virt.service.allocation.AvailableMemoryAllocationPolicy import com.atlarge.opendc.format.environment.sc20.Sc20EnvironmentReader import com.atlarge.opendc.format.trace.vm.VmTraceReader import kotlinx.coroutines.channels.Channel @@ -69,6 +70,7 @@ fun main(args: Array<String>) { println(simulationContext.clock.instant()) val scheduler = SimpleVirtProvisioningService( + AvailableMemoryAllocationPolicy(), simulationContext, environment.platforms[0].zones[0].services[ProvisioningService.Key], Sc20HypervisorMonitor() |
