diff options
| author | Dante Niewenhuis <d.niewenhuis@hotmail.com> | 2024-03-19 20:26:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-19 20:26:04 +0100 |
| commit | dff30fa60809c018101052f395b09cf17cb83ccb (patch) | |
| tree | 2c5f67b9424547061aaa0c6b6b85af9a125ec263 /opendc-experiments/opendc-experiments-portfolio/src/main/kotlin | |
| parent | 960b3d8a13c67ac4b7f479d5764b0b618fc9ea09 (diff) | |
Scenario and Portfolio update (#209)
* Initial commit
* Implemented a new systems of defining and running scenarios / portfolios. Scenarios and Portfolios can now be defined using JSON files similar to topologies. This allows user to define experiments without changing any KotLin code.
* Ran spotlessApply
Diffstat (limited to 'opendc-experiments/opendc-experiments-portfolio/src/main/kotlin')
2 files changed, 133 insertions, 0 deletions
diff --git a/opendc-experiments/opendc-experiments-portfolio/src/main/kotlin/org/opendc/experiments/scenario/ExamplePortfolio.kt b/opendc-experiments/opendc-experiments-portfolio/src/main/kotlin/org/opendc/experiments/scenario/ExamplePortfolio.kt new file mode 100644 index 00000000..b5b174b6 --- /dev/null +++ b/opendc-experiments/opendc-experiments-portfolio/src/main/kotlin/org/opendc/experiments/scenario/ExamplePortfolio.kt @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2022 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.scenario + +import org.opendc.compute.service.scheduler.ComputeSchedulerEnum +import org.opendc.experiments.base.models.portfolio.Portfolio +import org.opendc.experiments.base.models.scenario.AllocationPolicySpec +import org.opendc.experiments.base.models.scenario.FailureModelSpec +import org.opendc.experiments.base.models.scenario.Scenario +import org.opendc.experiments.base.models.scenario.ScenarioSpec +import org.opendc.experiments.base.models.scenario.TopologySpec +import org.opendc.experiments.base.models.scenario.WorkloadSpec +import org.opendc.experiments.base.models.scenario.WorkloadTypes +import org.opendc.experiments.base.models.scenario.getScenario + +/** + * A [Portfolio] that explores the difference between horizontal and vertical scaling. + */ +public fun getExamplePortfolio(): Portfolio { + val topologies = + listOf( + TopologySpec("resources/env/single.json"), + TopologySpec("resources/env/multi.json"), + ) + + val workloads = + listOf( + WorkloadSpec("resources/bitbrains-small", type = WorkloadTypes.ComputeWorkload), + ) + + val failureModel = FailureModelSpec(0.0) + val allocationPolicy = AllocationPolicySpec(ComputeSchedulerEnum.ActiveServers) + + val scenarios: Iterable<Scenario> = + topologies.flatMap { topology -> + workloads.map { workload -> + getScenario( + ScenarioSpec( + topology, + workload, + allocationPolicy, + failureModel, + ), + ) + } + } + + return Portfolio(scenarios) +} diff --git a/opendc-experiments/opendc-experiments-portfolio/src/main/kotlin/org/opendc/experiments/scenario/PortfolioCli.kt b/opendc-experiments/opendc-experiments-portfolio/src/main/kotlin/org/opendc/experiments/scenario/PortfolioCli.kt new file mode 100644 index 00000000..5f703164 --- /dev/null +++ b/opendc-experiments/opendc-experiments-portfolio/src/main/kotlin/org/opendc/experiments/scenario/PortfolioCli.kt @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2022 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. + */ + +@file:JvmName("PortfolioCli") + +package org.opendc.experiments.portfolio + +import com.github.ajalt.clikt.core.CliktCommand +import com.github.ajalt.clikt.parameters.options.default +import com.github.ajalt.clikt.parameters.options.defaultLazy +import com.github.ajalt.clikt.parameters.options.option +import com.github.ajalt.clikt.parameters.types.file +import com.github.ajalt.clikt.parameters.types.int +import org.opendc.experiments.base.models.portfolio.getPortfolio +import org.opendc.experiments.base.runner.runPortfolio +import java.io.File + +/** + * Main entrypoint of the application. + */ +public fun main(args: Array<String>): Unit = PortfolioCommand().main(args) + +/** + * Represents the command for the Portfolio experiments. + */ +internal class PortfolioCommand : CliktCommand(name = "portfolio") { + /** + * The path to the environment directory. + */ + private val portfolioPath by option("--portfolio-path", help = "path to portfolio file") + .file(canBeDir = true, canBeFile = false) + .defaultLazy { File("resources/portfolio.json") } + + /** + * The number of threads to use for parallelism. + */ + private val parallelism by option("-p", "--parallelism", help = "number of worker threads") + .int() + .default(Runtime.getRuntime().availableProcessors() - 1) + + override fun run() { + val portfolio = getPortfolio(portfolioPath) + runPortfolio(portfolio, parallelism) + } +} |
