summaryrefslogtreecommitdiff
path: root/simulator/opendc-compute
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-01-07 17:25:40 +0100
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-01-07 23:33:57 +0100
commit9cf24c9a8d3e96a29d9b111081bc3369aadd490d (patch)
tree4f378ee9f77d8623a67a403135a4010afd5f9000 /simulator/opendc-compute
parent74a4bff83bfb6366cc193d1fc9c4a07e49649649 (diff)
Refactor workflow service to schedule tasks onto VMs
This change updates the workflow service to delegate the resource scheduling logic to the virtualized resource provisioner.
Diffstat (limited to 'simulator/opendc-compute')
-rw-r--r--simulator/opendc-compute/opendc-compute-core/src/main/kotlin/org/opendc/compute/core/virt/service/VirtProvisioningService.kt5
-rw-r--r--simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimVirtDriver.kt16
-rw-r--r--simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimVirtProvisioningService.kt10
-rw-r--r--simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/allocation/ComparableAllocationPolicyLogic.kt2
-rw-r--r--simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimVirtDriverTest.kt2
5 files changed, 24 insertions, 11 deletions
diff --git a/simulator/opendc-compute/opendc-compute-core/src/main/kotlin/org/opendc/compute/core/virt/service/VirtProvisioningService.kt b/simulator/opendc-compute/opendc-compute-core/src/main/kotlin/org/opendc/compute/core/virt/service/VirtProvisioningService.kt
index ab96e0a3..3d722110 100644
--- a/simulator/opendc-compute/opendc-compute-core/src/main/kotlin/org/opendc/compute/core/virt/service/VirtProvisioningService.kt
+++ b/simulator/opendc-compute/opendc-compute-core/src/main/kotlin/org/opendc/compute/core/virt/service/VirtProvisioningService.kt
@@ -42,6 +42,11 @@ public interface VirtProvisioningService {
public suspend fun drivers(): Set<VirtDriver>
/**
+ * The number of hosts available in the system.
+ */
+ public val hostCount: Int
+
+ /**
* Submit the specified [Image] to the provisioning service.
*
* @param name The name of the server to deploy.
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 09eec1ef..249979a8 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
@@ -32,11 +32,10 @@ import org.opendc.compute.core.virt.HypervisorEvent
import org.opendc.compute.core.virt.driver.InsufficientMemoryOnServerException
import org.opendc.compute.core.virt.driver.VirtDriver
import org.opendc.core.services.ServiceRegistry
-import org.opendc.simulator.compute.SimExecutionContext
-import org.opendc.simulator.compute.SimHypervisor
-import org.opendc.simulator.compute.SimMachine
+import org.opendc.simulator.compute.*
import org.opendc.simulator.compute.interference.IMAGE_PERF_INTERFERENCE_MODEL
import org.opendc.simulator.compute.interference.PerformanceInterferenceModel
+import org.opendc.simulator.compute.model.MemoryUnit
import org.opendc.simulator.compute.workload.SimWorkload
import org.opendc.utils.flow.EventFlow
import java.time.Clock
@@ -72,7 +71,7 @@ public class SimVirtDriver(
/**
* The hypervisor to run multiple workloads.
*/
- private val hypervisor = SimHypervisor(
+ private val hypervisor = SimFairSharedHypervisor(
coroutineScope,
clock,
object : SimHypervisor.Listener {
@@ -126,7 +125,14 @@ public class SimVirtDriver(
events
)
availableMemory -= requiredMemory
- val vm = VirtualMachine(server, events, hypervisor.createMachine(ctx.machine))
+
+ val originalCpu = ctx.machine.cpus[0]
+ val processingNode = originalCpu.node.copy(coreCount = flavor.cpuCount)
+ val processingUnits = (0 until flavor.cpuCount).map { originalCpu.copy(id = it, node = processingNode) }
+ val memoryUnits = listOf(MemoryUnit("Generic", "Generic", 3200.0, flavor.memorySize))
+
+ val machine = SimMachineModel(processingUnits, memoryUnits)
+ val vm = VirtualMachine(server, events, hypervisor.createMachine(machine))
vms.add(vm)
vmStarted(vm)
eventFlow.emit(HypervisorEvent.VmsUpdated(this, vms.size, availableMemory))
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 0144fd69..17de3de7 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
@@ -54,7 +54,8 @@ public class SimVirtProvisioningService(
private val clock: Clock,
private val provisioningService: ProvisioningService,
public val allocationPolicy: AllocationPolicy,
- private val tracer: EventTracer
+ private val tracer: EventTracer,
+ private val schedulingQuantum: Long = 300000 // 5 minutes in milliseconds
) : VirtProvisioningService {
/**
* The logger instance to use.
@@ -134,6 +135,8 @@ public class SimVirtProvisioningService(
return availableHypervisors.map { it.driver }.toSet()
}
+ override val hostCount: Int = hypervisors.size
+
override suspend fun deploy(
name: String,
image: Image,
@@ -173,11 +176,10 @@ public class SimVirtProvisioningService(
return
}
- val quantum = 300000 // 5 minutes in milliseconds
// 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)
+ val delay = schedulingQuantum - (clock.millis() % schedulingQuantum)
val call = coroutineScope.launch {
delay(delay)
@@ -191,7 +193,7 @@ public class SimVirtProvisioningService(
val imagesToBeScheduled = incomingImages.toSet()
for (imageInstance in imagesToBeScheduled) {
- val requiredMemory = imageInstance.image.tags["required-memory"] as Long
+ val requiredMemory = imageInstance.flavor.memorySize
val selectedHv = allocationLogic.select(availableHypervisors, imageInstance)
if (selectedHv == null) {
diff --git a/simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/allocation/ComparableAllocationPolicyLogic.kt b/simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/allocation/ComparableAllocationPolicyLogic.kt
index 8defe8b7..4470eab9 100644
--- a/simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/allocation/ComparableAllocationPolicyLogic.kt
+++ b/simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/allocation/ComparableAllocationPolicyLogic.kt
@@ -40,7 +40,7 @@ public interface ComparableAllocationPolicyLogic : AllocationPolicy.Logic {
): HypervisorView? {
return hypervisors.asSequence()
.filter { hv ->
- val fitsMemory = hv.availableMemory >= (image.image.tags["required-memory"] as Long)
+ val fitsMemory = hv.availableMemory >= (image.flavor.memorySize)
val fitsCpu = hv.server.flavor.cpuCount >= image.flavor.cpuCount
fitsMemory && fitsCpu
}
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 a0c61f29..394e87c6 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
@@ -136,7 +136,7 @@ internal class SimVirtDriverTest {
assertAll(
{ assertEquals(emptyList<Throwable>(), scope.uncaughtExceptions, "No errors") },
- { assertEquals(2073600, requestedBurst, "Requested Burst does not match") },
+ { assertEquals(2082000, requestedBurst, "Requested Burst does not match") },
{ assertEquals(2013600, grantedBurst, "Granted Burst does not match") },
{ assertEquals(60000, overcommissionedBurst, "Overcommissioned Burst does not match") },
{ assertEquals(1200007, scope.currentTime) }