diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/ExperimentConfig.kt b/theodolite-quarkus/src/main/kotlin/theodolite/ExperimentConfig.kt deleted file mode 100644 index 5b2fb22c0fd88bf63a942c9b68a8a3042946ecd7..0000000000000000000000000000000000000000 --- a/theodolite-quarkus/src/main/kotlin/theodolite/ExperimentConfig.kt +++ /dev/null @@ -1,26 +0,0 @@ -package theodolite - -import theodolite.strategies.SearchAlgorithm - -data class ExperimentConfig( - val useCase: Int, - val expId: Int, - val dimValues: Array<Int>, - val replicass: Array<Int>, - val partitions: Int, - val cpuLimit: String, - val memoryLimit: String, - val executionMinutes: Float, - val prometheusBaseUrl: String, - val reset: Boolean, - val namespace: String, - val resultPath: String, - val configurations: Any, - val restrictionStrategy: SearchAlgorithm, - val searchStrategy: SearchStrategy, - val benchmark: Any, // TODO - val sloChecker: Any // TODO -) { - - -} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/ExperimentExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/ExperimentExecutor.kt deleted file mode 100644 index 9c68ca5cf69843d77d9376e2007b35fc01785f92..0000000000000000000000000000000000000000 --- a/theodolite-quarkus/src/main/kotlin/theodolite/ExperimentExecutor.kt +++ /dev/null @@ -1,9 +0,0 @@ -package theodolite - -class ExperimentExecutor( - val config: ExperimentConfig -) { - fun run() { - this.config.restrictionStrategy.restrictResource(); - } -} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/GreetingResource.kt b/theodolite-quarkus/src/main/kotlin/theodolite/GreetingResource.kt deleted file mode 100644 index 2cf79f2d805344ba2b19f8e0aea58ad682a5e36f..0000000000000000000000000000000000000000 --- a/theodolite-quarkus/src/main/kotlin/theodolite/GreetingResource.kt +++ /dev/null @@ -1,14 +0,0 @@ -package theodolite - -import javax.ws.rs.GET -import javax.ws.rs.Path -import javax.ws.rs.Produces -import javax.ws.rs.core.MediaType - -@Path("/hello-resteasy") -class GreetingResource { - - @GET - @Produces(MediaType.TEXT_PLAIN) - fun hello() = "Hello RESTEasy" -} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/Main.kt b/theodolite-quarkus/src/main/kotlin/theodolite/Main.kt index d606aedd87a2f5a2a3ad71fbf805589ba90c1e4d..26d1f112ddb927ffd51df994874a30ea1a458db6 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/Main.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/Main.kt @@ -7,28 +7,5 @@ object Main { @JvmStatic fun main(args: Array<String>) { println("Starting Benchmarks") - - val config: ExperimentConfig = ExperimentConfig( - exp_id = 0, - use_case = 1, - dim_values = arrayOf(1,2,3), - configurations = TODO(), - domain_restriction_strategy = TODO(), - cpu_limit = "1000m", - execution_minutes = 5f, - memory_limit = "4gb", - namespace = "default", - partitions = 10, - prometheus_base_url = "http://localhost:9090", - replicass = arrayOf(1,2,3), - reset = false, - result_path = "./results", - search_strategy = TODO(), - subexperiment_evaluator = TODO(), - subexperiment_executor = TODO() - ) - - val executor: ExperimentExecutor = ExperimentExecutor(config) - executor.run() } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt new file mode 100644 index 0000000000000000000000000000000000000000..e6ffc016552fbea01dbd124c1df1056ada681af3 --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt @@ -0,0 +1,8 @@ +package theodolite.execution + +import theodolite.util.LoadDimension +import theodolite.util.Resource + +interface BenchmarkExecutor { + fun runExperiment(load: LoadDimension, res: Resource): Boolean; +} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TestBenchmarkExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TestBenchmarkExecutor.kt new file mode 100644 index 0000000000000000000000000000000000000000..9fd2453c1d7d516a671fb09e18a7041e4abf05a7 --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TestBenchmarkExecutor.kt @@ -0,0 +1,12 @@ +package theodolite.execution + +import theodolite.execution.BenchmarkExecutor +import theodolite.util.LoadDimension +import theodolite.util.Resource + +class TestBenchmarkExecutor(val mockResults: Array<Array<Boolean>>): BenchmarkExecutor { + + override fun runExperiment(load: LoadDimension, res: Resource): Boolean { + return this.mockResults[load.get()][res.get()] + } +} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/BinarySearch.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/BinarySearch.kt deleted file mode 100644 index c9fd0f498d88fe89eaaa06655a3e3dd40b7c2d00..0000000000000000000000000000000000000000 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/BinarySearch.kt +++ /dev/null @@ -1,10 +0,0 @@ -package theodolite.strategies - -import theodolite.strategies.searchstrategy.Benchmark -import theodolite.strategies.searchstrategy.SearchStrategy - -class BinarySearch(benchmark: Benchmark) : SearchStrategy(benchmark) { - override fun findSuitableResources(load: Int, resources: List<Int>): Int { - - } -} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/EvenResourcesRestriction.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/EvenResourcesRestriction.kt deleted file mode 100644 index 24078a23dce707aad2758f1e86395beac5682717..0000000000000000000000000000000000000000 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/EvenResourcesRestriction.kt +++ /dev/null @@ -1,12 +0,0 @@ -package theodolite.strategies - -import theodolite.strategies.restriction.CompositeRestriction -import theodolite.strategies.restriction.Restriction - -class EvenResourcesRestriction(childRestriction: Restriction) : CompositeRestriction(childRestriction) { - override fun restrict(loads: List<Int>, resources: List<Int>) { - val filteredResources: List<Int> = resources.filter { x -> x % 2 == 0 }; - this.childRestriction.restrict(loads, filteredResources); - } - -} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/LinearSearch.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/LinearSearch.kt deleted file mode 100644 index 79938f7fa20a710a7289979c841658bfb2dcf640..0000000000000000000000000000000000000000 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/LinearSearch.kt +++ /dev/null @@ -1,14 +0,0 @@ -package theodolite.strategies - -import theodolite.strategies.searchstrategy.Benchmark -import theodolite.strategies.searchstrategy.SearchStrategy - -class LinearSearch(benchmark: Benchmark) : SearchStrategy(benchmark) { - - override fun findSuitableResources(load: Int, resources: List<Int>): Int { - for (res in resources) { - if (this.benchmark.execute(load, res)) return resources.indexOf(res); - } - return resources.size; - } -} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/LowerBoundRestriction.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/LowerBoundRestriction.kt deleted file mode 100644 index 157281a4c8c6da073a29e2ec802bb059cc5ecd7d..0000000000000000000000000000000000000000 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/LowerBoundRestriction.kt +++ /dev/null @@ -1,16 +0,0 @@ -package theodolite.strategies - -import theodolite.strategies.restriction.PrimitiveRestriction -import theodolite.strategies.searchstrategy.SearchStrategy - -class LowerBoundRestriction(searchStrategy: SearchStrategy) : PrimitiveRestriction(searchStrategy) { - override fun restrict(loads: List<Int>, resources: List<Int>): List<Int> { - val lowerBounds: MutableList<Int> = ArrayList<Int>(); - var lowerBound = 0; - for (load in loads) { - lowerBound = this.searchStrategy.findSuitableResources(load, resources.subList(lowerBound, resources.size)); - lowerBounds.add(lowerBound); - } - return lowerBounds; - } -} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/LowerBoundRestriction.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/LowerBoundRestriction.kt new file mode 100644 index 0000000000000000000000000000000000000000..fc5b6d5385a3fd97fb224219ee5ec0844b44d414 --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/LowerBoundRestriction.kt @@ -0,0 +1,16 @@ +package theodolite.strategies.restriction + +import theodolite.util.Results +import theodolite.strategies.searchstrategy.RestrictionStrategy +import theodolite.util.LoadDimension +import theodolite.util.Resource + +class LowerBoundRestriction(results: Results, loads: List<LoadDimension>) : RestrictionStrategy(results, loads) { + override fun next(load: LoadDimension, resources: List<Resource>): List<Resource> { + var lowerBound: Resource? = this.results.getRequiredInstances(load) + if(lowerBound == null) { + lowerBound = Resource(0) // TODO handle the null case + } + return resources.filter{x -> x.get() >= lowerBound.get()} + } +} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/Benchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/Benchmark.kt deleted file mode 100644 index eb3e22a362b61510bab97b4e518864d64fa0582a..0000000000000000000000000000000000000000 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/Benchmark.kt +++ /dev/null @@ -1,7 +0,0 @@ -package theodolite.strategies.searchstrategy - -class Benchmark { - fun execute(load: Int, res: Int): Boolean { - return true; - } -} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt new file mode 100644 index 0000000000000000000000000000000000000000..1bc22f7ca842207fc8c490dac33677b72e10c3e3 --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt @@ -0,0 +1,37 @@ +package theodolite.strategies.searchstrategy + +import theodolite.execution.BenchmarkExecutor +import theodolite.util.LoadDimension +import theodolite.util.Resource +import java.lang.IllegalArgumentException + +class BinarySearch(benchmarkExecutor: BenchmarkExecutor) : SearchStrategy(benchmarkExecutor) { + override fun findSuitableResources(load: LoadDimension, resources: List<Resource>): Resource? { + val result = search(load, resources, 0, resources.size - 1) + if( result == -1 ) { + return null; + } + return resources[result] + } + + private fun search (load: LoadDimension, resources: List<Resource>, lower: Int, upper: Int): Int { + if (lower + 1 < upper ) { + throw IllegalArgumentException() + } + if (lower >= upper ) { + if (this.benchmarkExecutor.runExperiment(load, resources[upper])) return upper; + else { + if (lower + 1 == resources.size) return - 1 + return lower + 1; + } + } else { + val mid = (upper + lower) / 2 + if (this.benchmarkExecutor.runExperiment(load, resources[mid])) { + return search(load, resources, lower, mid - 1 ); + } else { + return search(load, resources, mid + 1 , upper); + } + } + } + +} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/CompositeStrategy.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/CompositeStrategy.kt new file mode 100644 index 0000000000000000000000000000000000000000..79c34e3260694fa93ef796e9ee1f3f09665d5e94 --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/CompositeStrategy.kt @@ -0,0 +1,16 @@ +package theodolite.strategies.searchstrategy + +import theodolite.execution.BenchmarkExecutor +import theodolite.util.LoadDimension +import theodolite.util.Resource + +class CompositeStrategy(benchmarkExecutor: BenchmarkExecutor, val searchStrategy: SearchStrategy, val restrictionStrategies: List<RestrictionStrategy>) : SearchStrategy(benchmarkExecutor) { + + override fun findSuitableResources(load: LoadDimension,resources: List<Resource>): Resource? { + var restrictedResources: List<Resource> = resources + for (strategy in this.restrictionStrategies) { + restrictedResources.intersect(strategy.next(load, resources)) + } + return this.searchStrategy.findSuitableResources(load, restrictedResources) + } +} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt new file mode 100644 index 0000000000000000000000000000000000000000..919689ed925fd331ee4afa8d2c65e170d637f320 --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt @@ -0,0 +1,15 @@ +package theodolite.strategies.searchstrategy + +import theodolite.execution.BenchmarkExecutor +import theodolite.util.LoadDimension +import theodolite.util.Resource + +class LinearSearch(benchmarkExecutor: BenchmarkExecutor) : SearchStrategy(benchmarkExecutor) { + + override fun findSuitableResources(load: LoadDimension, resources: List<Resource>): Resource? { + for (res in resources) { + if (this.benchmarkExecutor.runExperiment(load, res)) return res; + } + return null; + } +} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/RestrictionStrategy.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/RestrictionStrategy.kt new file mode 100644 index 0000000000000000000000000000000000000000..7a6e43ce008603101d20685d195523ca77beef71 --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/RestrictionStrategy.kt @@ -0,0 +1,9 @@ +package theodolite.strategies.searchstrategy + +import theodolite.util.Results +import theodolite.util.LoadDimension +import theodolite.util.Resource + +abstract class RestrictionStrategy(val results: Results, val loads: List<LoadDimension>) { + public abstract fun next(load: LoadDimension, resources: List<Resource>): List<Resource>; +} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt index b42e78c9edb01b32bcb5be61c385296f9ac71c95..48749978475c63c3fb667e92054654c5f9a9260c 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt @@ -1,5 +1,9 @@ package theodolite.strategies.searchstrategy -abstract class SearchStrategy(val benchmark: Benchmark) { - abstract fun findSuitableResources(load: Int, resources: List<Int>): Int; +import theodolite.execution.BenchmarkExecutor +import theodolite.util.LoadDimension +import theodolite.util.Resource + +abstract class SearchStrategy(val benchmarkExecutor: BenchmarkExecutor) { + abstract fun findSuitableResources(load: LoadDimension, resources: List<Resource>): Resource?; } \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/LoadDimension.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/LoadDimension.kt new file mode 100644 index 0000000000000000000000000000000000000000..84de466a86ecd094d905a2b8203cce663f0802fb --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/LoadDimension.kt @@ -0,0 +1,17 @@ +package theodolite.util + +class LoadDimension(val number: Int) { + public fun get(): Int { + return this.number; + } + public override fun equals(other: Any?): Boolean { + if (other is LoadDimension) { + return this.get() == other.get() + } + return false + } + + override fun hashCode(): Int { + return this.get().hashCode() + } +} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/Resource.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/Resource.kt new file mode 100644 index 0000000000000000000000000000000000000000..9d1478c47ed4810ef44eba0e2b248763dd385e13 --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/Resource.kt @@ -0,0 +1,18 @@ +package theodolite.util + +class Resource(val number: Int) { + public fun get(): Int { + return this.number; + } + + public override fun equals(other: Any?): Boolean { + if (other is Resource) { + return this.get() == other.get() + } + return false + } + + override fun hashCode(): Int { + return this.get().hashCode() + } +} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/Results.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/Results.kt new file mode 100644 index 0000000000000000000000000000000000000000..1a4107612b8007346300c480a269b885369cc8aa --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/Results.kt @@ -0,0 +1,32 @@ +package theodolite.util + +import theodolite.util.LoadDimension +import theodolite.util.Resource +import kotlin.math.exp + +class Results { + // load, instances + private val results: MutableMap<Pair<LoadDimension, Resource>, Boolean> = mutableMapOf() + + public fun setResult(experiment: Pair<LoadDimension, Resource>, successful: Boolean) { + this.results.put(experiment, successful) + } + + public fun getResult (experiment: Pair<LoadDimension, Resource>): Boolean? { + return this.results.get(experiment) + } + + public fun getRequiredInstances(load: LoadDimension): Resource? { + var requiredInstances: Resource? = null; + for(experiment in results) { + if(experiment.key.first == load && experiment.value){ + if(requiredInstances == null) { + requiredInstances = experiment.key.second + }else if (experiment.key.second.get() < requiredInstances.get()) { + requiredInstances = experiment.key.second + } + } + } + return requiredInstances + } +} \ No newline at end of file diff --git a/theodolite-quarkus/src/native-test/kotlin/theodolite/NativeGreetingResourceIT.kt b/theodolite-quarkus/src/native-test/kotlin/theodolite/NativeGreetingResourceIT.kt index 26e8900ffe1a17b71fc23e1327fa649421548e36..6f17e6294d428a769d5e02958628820a37e42f66 100644 --- a/theodolite-quarkus/src/native-test/kotlin/theodolite/NativeGreetingResourceIT.kt +++ b/theodolite-quarkus/src/native-test/kotlin/theodolite/NativeGreetingResourceIT.kt @@ -3,4 +3,4 @@ package theodolite import io.quarkus.test.junit.NativeImageTest @NativeImageTest -class NativeGreetingResourceIT : GreetingResourceTest() \ No newline at end of file +class NativeGreetingResourceIT : CompositeStrategyTest() \ No newline at end of file diff --git a/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt b/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt new file mode 100644 index 0000000000000000000000000000000000000000..3bf4815e1843dc88c1880631603a74cdc96e5a4f --- /dev/null +++ b/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt @@ -0,0 +1,49 @@ +package theodolite + +import io.quarkus.test.junit.QuarkusTest +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test +import theodolite.strategies.searchstrategy.LinearSearch +import theodolite.strategies.restriction.LowerBoundRestriction +import theodolite.strategies.searchstrategy.CompositeStrategy +import theodolite.execution.TestBenchmarkExecutor +import theodolite.util.LoadDimension +import theodolite.util.Resource +import theodolite.util.Results + +@QuarkusTest +class CompositeStrategyTest { + + @Test + fun testEnd2End() { + val mockResults = arrayOf( + arrayOf( true , true , true , true , true , true , true), + arrayOf( false, false, true , true , true , true , true), + arrayOf( false, false, true , true , true , true , true), + arrayOf( false, false, false, true , true , true , true), + arrayOf( false, false, false, false, true , true , true), + arrayOf( false, false, false, false, false, false, true), + arrayOf( false, false, false, false, false, false, false) + ) + val mockLoads: List<LoadDimension> = (0..6).map{number -> LoadDimension(number)} + val mockResources: List<Resource> = (0..6).map{number -> Resource(number)} + val benchmarkExecutor: TestBenchmarkExecutor = TestBenchmarkExecutor(mockResults) + val linearSearch: LinearSearch = LinearSearch(benchmarkExecutor); + val results: Results = Results(); + val lowerBoundRestriction: LowerBoundRestriction = LowerBoundRestriction(results, mockLoads); + val strategy: CompositeStrategy = CompositeStrategy(benchmarkExecutor, linearSearch, listOf(lowerBoundRestriction)) + + val actual: ArrayList<Resource?> = ArrayList<Resource?>() + val expected: ArrayList<Resource?> = ArrayList(listOf(0,2,2,3,4,6).map{ x -> Resource(x)}) + expected.add(null) + + for(load in mockLoads) { + actual.add(strategy.findSuitableResources(load, mockResources)) + } + + assertEquals(actual, expected) + } + + + +} \ No newline at end of file diff --git a/theodolite-quarkus/src/test/kotlin/theodolite/GreetingResourceTest.kt b/theodolite-quarkus/src/test/kotlin/theodolite/GreetingResourceTest.kt deleted file mode 100644 index 048093a7ec71389f7bfc59e22f7f4911ef485b94..0000000000000000000000000000000000000000 --- a/theodolite-quarkus/src/test/kotlin/theodolite/GreetingResourceTest.kt +++ /dev/null @@ -1,20 +0,0 @@ -package theodolite - -import io.quarkus.test.junit.QuarkusTest -import io.restassured.RestAssured.given -import org.hamcrest.CoreMatchers.`is` -import org.junit.jupiter.api.Test - -@QuarkusTest -class GreetingResourceTest { - - @Test - fun testHelloEndpoint() { - given() - .`when`().get("/hello-resteasy") - .then() - .statusCode(200) - .body(`is`("Hello RESTEasy")) - } - -} \ No newline at end of file