diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-09-22 10:28:37 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-09-22 14:49:35 +0200 |
| commit | 6171ab09f1df2ab3475a7b28ece383a9f87a77c5 (patch) | |
| tree | 54a7ae4ef7c482dfdc04ba3eef37ab428bee3b33 /opendc-compute/opendc-compute-workload/src/main/kotlin | |
| parent | 507ff6223d277ebc6744b92b4030d94f20a92a02 (diff) | |
refactor(sim/compute): Extract Random dependency from interference model
This change moves the Random dependency outside the interference model,
to allow the interference model to be completely immutable and passable
between different simulations.
Diffstat (limited to 'opendc-compute/opendc-compute-workload/src/main/kotlin')
| -rw-r--r-- | opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeServiceHelper.kt | 24 |
1 files changed, 14 insertions, 10 deletions
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 fddb4890..879ef072 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 @@ -54,6 +54,7 @@ public class ComputeServiceHelper( private val context: CoroutineContext, private val clock: Clock, scheduler: ComputeScheduler, + seed: Long, private val failureModel: FailureModel? = null, private val interferenceModel: VmInterferenceModel? = null, schedulingQuantum: Duration = Duration.ofMinutes(5) @@ -66,12 +67,17 @@ public class ComputeServiceHelper( /** * The [FlowEngine] to simulate the hosts. */ - private val _engine = FlowEngine(context, clock) + private val engine = FlowEngine(context, clock) /** * The hosts that belong to this class. */ - private val _hosts = mutableSetOf<SimHost>() + private val hosts = mutableSetOf<SimHost>() + + /** + * The source of randomness. + */ + private val random = SplittableRandom(seed) init { val service = createService(scheduler, schedulingQuantum) @@ -82,18 +88,15 @@ public class ComputeServiceHelper( * Run a simulation of the [ComputeService] by replaying the workload trace given by [trace]. * * @param trace The trace to simulate. - * @param seed The seed for the simulation. * @param servers A list to which the created servers is added. * @param submitImmediately A flag to indicate that the servers are scheduled immediately (so not at their start time). */ public suspend fun run( trace: List<VirtualMachine>, - seed: Long, servers: MutableList<Server>? = null, submitImmediately: Boolean = false ) { - val random = Random(seed) - val injector = failureModel?.createInjector(context, clock, service, random) + val injector = failureModel?.createInjector(context, clock, service, Random(random.nextLong())) val client = service.newClient() // Create new image for the virtual machine @@ -170,14 +173,15 @@ public class ComputeServiceHelper( spec.model, spec.meta, context, - _engine, + engine, spec.hypervisor, + random, powerDriver = spec.powerDriver, interferenceDomain = interferenceModel?.newDomain(), optimize = optimize ) - require(_hosts.add(host)) { "Host with uid ${spec.uid} already exists" } + require(hosts.add(host)) { "Host with uid ${spec.uid} already exists" } service.addHost(host) return host @@ -186,11 +190,11 @@ public class ComputeServiceHelper( override fun close() { service.close() - for (host in _hosts) { + for (host in hosts) { host.close() } - _hosts.clear() + hosts.clear() } /** |
