Skip to content

Commit

Permalink
Merge pull request #32 from Radu-Nicolae/fix-revert
Browse files Browse the repository at this point in the history
Revert "updated ScenarioFactory and ScenarioSpec (atlarge-research#239)"
  • Loading branch information
Radu-Nicolae authored Aug 8, 2024
2 parents 4ec20f3 + 9c0e195 commit c18da93
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package org.opendc.experiments.base.runner

import CheckpointModelSpec
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
Expand All @@ -35,7 +36,6 @@ import org.opendc.compute.api.ServerWatcher
import org.opendc.compute.failure.models.FailureModel
import org.opendc.compute.service.ComputeService
import org.opendc.compute.workload.VirtualMachine
import org.opendc.experiments.base.scenario.specs.CheckpointModelSpec
import org.opendc.experiments.base.scenario.specs.FailureModelSpec
import org.opendc.experiments.base.scenario.specs.createFailureModel
import java.time.InstantSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package org.opendc.experiments.base.runner

import getWorkloadType
import me.tongfei.progressbar.ProgressBarBuilder
import me.tongfei.progressbar.ProgressBarStyle
import org.opendc.compute.carbon.CarbonTrace
Expand All @@ -36,7 +37,6 @@ import org.opendc.compute.telemetry.export.parquet.ParquetComputeMonitor
import org.opendc.compute.topology.clusterTopology
import org.opendc.compute.workload.ComputeWorkloadLoader
import org.opendc.experiments.base.scenario.Scenario
import org.opendc.experiments.base.scenario.specs.getWorkloadType
import org.opendc.simulator.kotlin.runSimulation
import java.io.File
import java.time.Duration
Expand All @@ -60,7 +60,7 @@ public fun runScenarios(

setupOutputFolderStructure(scenarios[0].outputFolder)

for (scenario in scenarios) {
for ((i, scenario) in scenarios.withIndex()) {
val pool = ForkJoinPool(parallelism)
println(
"\n\n$ansiGreen================================================================================$ansiReset",
Expand All @@ -70,6 +70,7 @@ public fun runScenarios(
runScenario(
scenario,
pool,
i,
)
}
}
Expand All @@ -84,14 +85,15 @@ public fun runScenarios(
public fun runScenario(
scenario: Scenario,
pool: ForkJoinPool,
index: Int = -1,
) {
val pb =
ProgressBarBuilder().setInitialMax(scenario.runs.toLong()).setStyle(ProgressBarStyle.ASCII)
.setTaskName("Simulating...").build()

pool.submit {
LongStream.range(0, scenario.runs.toLong()).parallel().forEach {
runScenario(scenario, scenario.initialSeed + it)
runScenario(scenario, scenario.initialSeed + it, index)
pb.step()
}
pb.close()
Expand All @@ -107,6 +109,7 @@ public fun runScenario(
public fun runScenario(
scenario: Scenario,
seed: Long,
index: Int = 0,
): Unit =
runSimulation {
val serviceDomain = "compute.opendc.org"
Expand All @@ -126,7 +129,7 @@ public fun runScenario(

val carbonTrace = getCarbonTrace(scenario.carbonTracePath)
val startTime = Duration.ofMillis(vms.minOf { it.startTime }.toEpochMilli())
addExportModel(provisioner, serviceDomain, scenario, seed, startTime, carbonTrace, scenario.id)
addExportModel(provisioner, serviceDomain, scenario, seed, startTime, carbonTrace, index)

val service = provisioner.registry.resolve(serviceDomain, ComputeService::class.java)!!
service.replay(timeSource, vms, failureModelSpec = scenario.failureModelSpec, seed = seed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

package org.opendc.experiments.base.scenario

import org.opendc.experiments.base.scenario.specs.AllocationPolicySpec
import org.opendc.experiments.base.scenario.specs.CheckpointModelSpec
import org.opendc.experiments.base.scenario.specs.ExportModelSpec
import AllocationPolicySpec
import CheckpointModelSpec
import ExportModelSpec
import ScenarioTopologySpec
import WorkloadSpec
import org.opendc.experiments.base.scenario.specs.FailureModelSpec
import org.opendc.experiments.base.scenario.specs.ScenarioTopologySpec
import org.opendc.experiments.base.scenario.specs.WorkloadSpec

/**
* A data class representing a scenario for a set of experiments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
package org.opendc.experiments.base.scenario

import org.opendc.experiments.base.scenario.specs.ScenarioSpec
import org.opendc.experiments.base.scenario.specs.ScenariosSpec
import java.io.File

private val scenarioReader = ScenarioReader()
Expand Down Expand Up @@ -53,38 +52,48 @@ public fun getScenarios(file: File): List<Scenario> {
* Returns a list of Scenarios from a given ScenarioSpec by generating all possible combinations of
* workloads, allocation policies, failure models, and export models within a topology.
*
* @param scenariosSpec The ScenarioSpec containing the scenario specifications.
* @param scenarioSpec The ScenarioSpec containing the scenario specifications.
* @return A list of Scenarios.
*/
public fun getScenarios(scenariosSpec: ScenariosSpec): List<Scenario> {
val outputFolder = scenariosSpec.outputFolder + "/" + scenariosSpec.name
public fun getScenarios(scenarioSpec: ScenarioSpec): List<Scenario> {
val outputFolder = scenarioSpec.outputFolder + "/" + scenarioSpec.name
File(outputFolder).mkdirs()

val trackrPath = "$outputFolder/trackr.json"
File(trackrPath).createNewFile()

val scenarios = mutableListOf<Scenario>()

val cartesianInput = scenariosSpec.getCartesian()

for ((scenarioID, scenarioSpec) in cartesianInput.withIndex()) {
val scenario =
Scenario(
id = scenarioID,
topologySpec = scenarioSpec.topology,
workloadSpec = scenarioSpec.workload,
allocationPolicySpec = scenarioSpec.allocationPolicy,
failureModelSpec = scenarioSpec.failureModel,
checkpointModelSpec = scenarioSpec.checkpointModel,
carbonTracePath = scenarioSpec.carbonTracePath,
exportModelSpec = scenarioSpec.exportModel,
outputFolder = outputFolder,
name = scenarioID.toString(),
runs = scenariosSpec.runs,
initialSeed = scenariosSpec.initialSeed,
)
trackScenario(scenarioSpec, outputFolder)
scenarios.add(scenario)
for ((scenarioID, scenarioTopologySpec) in scenarioSpec.topologies.withIndex()) {
for (workloadSpec in scenarioSpec.workloads) {
for (allocationPolicySpec in scenarioSpec.allocationPolicies) {
for (failureModelSpec in scenarioSpec.failureModels) {
for (checkpointModelSpec in scenarioSpec.checkpointModels) {
for (carbonTracePath in scenarioSpec.carbonTracePaths) {
for (exportModelSpec in scenarioSpec.exportModels) {
val scenario =
Scenario(
id = scenarioID,
topologySpec = scenarioTopologySpec,
workloadSpec = workloadSpec,
allocationPolicySpec = allocationPolicySpec,
failureModelSpec = failureModelSpec,
checkpointModelSpec = checkpointModelSpec,
carbonTracePath = carbonTracePath,
exportModelSpec = exportModelSpec,
outputFolder = outputFolder,
name = scenarioID.toString(),
runs = scenarioSpec.runs,
initialSeed = scenarioSpec.initialSeed,
)
trackScenario(scenarioSpec, outputFolder, scenario)
scenarios.add(scenario)
}
}
}
}
}
}
}

return scenarios
Expand All @@ -93,7 +102,7 @@ public fun getScenarios(scenariosSpec: ScenariosSpec): List<Scenario> {
/**
* Writes a ScenarioSpec to a file.
*
* @param scenariosSpec The ScenarioSpec.
* @param scenarioSpec The ScenarioSpec.
* @param outputFolder The output folder path.
* @param scenario The Scenario.
* @param topologySpec The TopologySpec.
Expand All @@ -102,10 +111,24 @@ public fun getScenarios(scenariosSpec: ScenariosSpec): List<Scenario> {
public fun trackScenario(
scenarioSpec: ScenarioSpec,
outputFolder: String,
scenario: Scenario,
) {
val trackrPath = "$outputFolder/trackr.json"
scenarioWriter.write(
scenarioSpec,
ScenarioSpec(
id = scenario.id,
name = scenarioSpec.name,
topologies = listOf(scenario.topologySpec),
workloads = listOf(scenario.workloadSpec),
allocationPolicies = listOf(scenario.allocationPolicySpec),
failureModels = listOf(scenario.failureModelSpec),
checkpointModels = listOf(scenario.checkpointModelSpec),
carbonTracePaths = listOf(scenario.carbonTracePath),
exportModels = listOf(scenario.exportModelSpec),
outputFolder = scenario.outputFolder,
initialSeed = scenario.initialSeed,
runs = scenario.runs,
),
File(trackrPath),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ package org.opendc.experiments.base.scenario
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import org.opendc.experiments.base.scenario.specs.ScenariosSpec
import org.opendc.experiments.base.scenario.specs.ScenarioSpec
import java.io.File
import java.io.InputStream
import java.nio.file.Path
Expand All @@ -36,24 +36,24 @@ public class ScenarioReader {
private val jsonReader = Json

@OptIn(ExperimentalSerializationApi::class)
public fun read(file: File): ScenariosSpec {
public fun read(file: File): ScenarioSpec {
val input = file.inputStream()

return jsonReader.decodeFromStream<ScenariosSpec>(input)
return jsonReader.decodeFromStream<ScenarioSpec>(input)
}

@OptIn(ExperimentalSerializationApi::class)
public fun read(path: Path): ScenariosSpec {
public fun read(path: Path): ScenarioSpec {
val input = path.inputStream()

return jsonReader.decodeFromStream<ScenariosSpec>(input)
return jsonReader.decodeFromStream<ScenarioSpec>(input)
}

/**
* Read the specified [input].
*/
@OptIn(ExperimentalSerializationApi::class)
public fun read(input: InputStream): ScenariosSpec {
return jsonReader.decodeFromStream<ScenariosSpec>(input)
public fun read(input: InputStream): ScenarioSpec {
return jsonReader.decodeFromStream<ScenarioSpec>(input)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ScenarioWriter {
private val json = Json { prettyPrint = true }

/**
* Write the given [scenariosSpec] to the given [file].
* Write the given [scenarioSpec] to the given [file].
*/
public fun write(
scenarioSpec: ScenarioSpec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
* SOFTWARE.
*/

package org.opendc.experiments.base.scenario.specs

import kotlinx.serialization.Serializable
import org.opendc.compute.service.scheduler.ComputeSchedulerEnum

Expand All @@ -34,7 +32,7 @@ import org.opendc.compute.service.scheduler.ComputeSchedulerEnum
*/
@Serializable
public data class AllocationPolicySpec(
val policyType: ComputeSchedulerEnum = ComputeSchedulerEnum.Mem,
val policyType: ComputeSchedulerEnum,
) {
public val name: String = policyType.toString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
* SOFTWARE.
*/

package org.opendc.experiments.base.scenario.specs

import kotlinx.serialization.Serializable

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
* SOFTWARE.
*/

package org.opendc.experiments.base.scenario.specs

import kotlinx.serialization.Serializable

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
* SOFTWARE.
*/

package org.opendc.experiments.base.scenario.specs

import kotlinx.serialization.Serializable

@Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2024 AtLarge Research
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package org.opendc.experiments.base.scenario.specs

import AllocationPolicySpec
import CheckpointModelSpec
import ExportModelSpec
import ScenarioTopologySpec
import WorkloadSpec
import kotlinx.serialization.Serializable
import java.util.UUID

/**
* specification describing a scenario
*
* @property topologies
* @property workloads
* @property allocationPolicies
* @property failureModels
* @property exportModels
* @property outputFolder
* @property initialSeed
* @property runs
*/
@Serializable
public data class ScenarioSpec(
var id: Int = -1,
var name: String = "",
val topologies: List<ScenarioTopologySpec>,
val workloads: List<WorkloadSpec>,
val allocationPolicies: List<AllocationPolicySpec>,
val failureModels: List<FailureModelSpec?> = listOf(null),
val checkpointModels: List<CheckpointModelSpec?> = listOf(null),
val carbonTracePaths: List<String?> = listOf(null),
val exportModels: List<ExportModelSpec> = listOf(ExportModelSpec()),
val outputFolder: String = "output",
val initialSeed: Int = 0,
val runs: Int = 1,
) {
init {
require(runs > 0) { "The number of runs should always be positive" }

// generate name if not provided
// TODO: improve this
if (name == "") {
name = "unnamed-simulation-${UUID.randomUUID().toString().substring(0, 4)}"
// "workload=${workloads[0].name}_topology=${topologies[0].name}_allocationPolicy=${allocationPolicies[0].name}"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
* SOFTWARE.
*/

package org.opendc.experiments.base.scenario.specs

import kotlinx.serialization.Serializable
import java.io.File

Expand Down
Loading

0 comments on commit c18da93

Please sign in to comment.