From 5a365dbc068f2a8cdfa9813c39cc84bb30e15637 Mon Sep 17 00:00:00 2001 From: Dante Niewenhuis Date: Fri, 25 Oct 2024 13:32:41 +0200 Subject: Rewrote the FlowEngine (#256) * Removed unused components. Updated tests. Improved checkpointing model Improved model, started with SimPowerSource implemented FailureModels and Checkpointing First working version midway commit first update All simulation are now run with a single CPU and single MemoryUnit. multi CPUs are combined into one. This is for performance and explainability. * fixed merge conflicts * Updated M3SA paths. * Fixed small typo --- opendc-faas/opendc-faas-simulator/build.gradle.kts | 36 ---- .../opendc/faas/simulator/SimFunctionDeployer.kt | 197 --------------------- .../opendc/faas/simulator/delay/ColdStartModel.kt | 69 -------- .../opendc/faas/simulator/delay/DelayInjector.kt | 37 ---- .../simulator/delay/StochasticDelayInjector.kt | 37 ---- .../faas/simulator/delay/ZeroDelayInjector.kt | 29 --- .../faas/simulator/workload/SimFaaSWorkload.kt | 35 ---- .../simulator/workload/SimFaaSWorkloadMapper.kt | 37 ---- .../workload/SimMetaFaaSWorkloadMapper.kt | 34 ---- .../opendc/faas/simulator/SimFaaSServiceTest.kt | 116 ------------ 10 files changed, 627 deletions(-) delete mode 100644 opendc-faas/opendc-faas-simulator/build.gradle.kts delete mode 100644 opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/SimFunctionDeployer.kt delete mode 100644 opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/delay/ColdStartModel.kt delete mode 100644 opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/delay/DelayInjector.kt delete mode 100644 opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/delay/StochasticDelayInjector.kt delete mode 100644 opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/delay/ZeroDelayInjector.kt delete mode 100644 opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/workload/SimFaaSWorkload.kt delete mode 100644 opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/workload/SimFaaSWorkloadMapper.kt delete mode 100644 opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/workload/SimMetaFaaSWorkloadMapper.kt delete mode 100644 opendc-faas/opendc-faas-simulator/src/test/kotlin/org/opendc/faas/simulator/SimFaaSServiceTest.kt (limited to 'opendc-faas/opendc-faas-simulator') diff --git a/opendc-faas/opendc-faas-simulator/build.gradle.kts b/opendc-faas/opendc-faas-simulator/build.gradle.kts deleted file mode 100644 index 20374324..00000000 --- a/opendc-faas/opendc-faas-simulator/build.gradle.kts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - -description = "Simulator for the OpenDC FaaS platform" - -// Build configuration -plugins { - `kotlin-library-conventions` -} - -dependencies { - api(projects.opendcFaas.opendcFaasService) - api(projects.opendcSimulator.opendcSimulatorCompute) - - testImplementation(projects.opendcSimulator.opendcSimulatorCore) - testRuntimeOnly(libs.slf4j.simple) -} diff --git a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/SimFunctionDeployer.kt b/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/SimFunctionDeployer.kt deleted file mode 100644 index c81dc523..00000000 --- a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/SimFunctionDeployer.kt +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (c) 2021 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.faas.simulator - -import kotlinx.coroutines.CancellationException -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Job -import kotlinx.coroutines.cancel -import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.delay -import kotlinx.coroutines.isActive -import kotlinx.coroutines.launch -import kotlinx.coroutines.suspendCancellableCoroutine -import org.opendc.common.Dispatcher -import org.opendc.common.asCoroutineDispatcher -import org.opendc.faas.service.FunctionObject -import org.opendc.faas.service.deployer.FunctionDeployer -import org.opendc.faas.service.deployer.FunctionInstance -import org.opendc.faas.service.deployer.FunctionInstanceListener -import org.opendc.faas.service.deployer.FunctionInstanceState -import org.opendc.faas.simulator.delay.DelayInjector -import org.opendc.faas.simulator.workload.SimFaaSWorkloadMapper -import org.opendc.faas.simulator.workload.SimMetaFaaSWorkloadMapper -import org.opendc.simulator.compute.SimBareMetalMachine -import org.opendc.simulator.compute.SimMachine -import org.opendc.simulator.compute.model.MachineModel -import org.opendc.simulator.compute.runWorkload -import org.opendc.simulator.flow2.FlowEngine -import java.util.ArrayDeque -import kotlin.coroutines.Continuation -import kotlin.coroutines.resume -import kotlin.coroutines.resumeWithException - -/** - * A [FunctionDeployer] that uses that simulates the [FunctionInstance]s. - */ -public class SimFunctionDeployer( - private val dispatcher: Dispatcher, - private val model: MachineModel, - private val delayInjector: DelayInjector, - private val mapper: SimFaaSWorkloadMapper = SimMetaFaaSWorkloadMapper(), -) : FunctionDeployer, AutoCloseable { - /** - * The [CoroutineScope] of this deployer. - */ - private val scope = CoroutineScope(dispatcher.asCoroutineDispatcher() + Job()) - - override fun deploy( - function: FunctionObject, - listener: FunctionInstanceListener, - ): Instance { - val instance = Instance(function, listener) - instance.start() - return instance - } - - /** - * A simulated [FunctionInstance]. - */ - public inner class Instance(override val function: FunctionObject, private val listener: FunctionInstanceListener) : - FunctionInstance { - /** - * The workload associated with this instance. - */ - private val workload = mapper.createWorkload(function) - - /** - * The machine that will execute the workloads. - */ - public val machine: SimMachine = - SimBareMetalMachine.create( - FlowEngine.create(dispatcher).newGraph(), - model, - ) - - /** - * The job associated with the lifecycle of the instance. - */ - private var job: Job? = null - - /** - * The invocation request queue. - */ - private val queue = ArrayDeque() - - /** - * A channel used to signal that new invocations have been enqueued. - */ - private val chan = Channel(Channel.RENDEZVOUS) - - override var state: FunctionInstanceState = FunctionInstanceState.Provisioning - set(value) { - if (field != value) { - listener.onStateChanged(this, value) - } - - field = value - } - - override suspend fun invoke() { - check(state != FunctionInstanceState.Deleted) { "Function instance has been released" } - return suspendCancellableCoroutine { cont -> - queue.add(InvocationRequest(cont)) - chan.trySend(Unit) - } - } - - override fun close() { - state = FunctionInstanceState.Deleted - stop() - machine.cancel() - } - - override fun toString(): String = "FunctionInstance[state=$state]" - - /** - * Start the function instance. - */ - internal fun start() { - check(state == FunctionInstanceState.Provisioning) { "Invalid state of function instance" } - job = - scope.launch { - delay(delayInjector.getColdStartDelay(this@Instance)) - - launch { - try { - machine.runWorkload(workload) - } finally { - state = FunctionInstanceState.Deleted - } - } - - while (isActive) { - if (queue.isEmpty()) { - chan.receive() - } - - state = FunctionInstanceState.Active - while (queue.isNotEmpty()) { - val request = queue.poll() - try { - workload.invoke() - request.cont.resume(Unit) - } catch (cause: CancellationException) { - request.cont.resumeWithException(cause) - throw cause - } catch (cause: Throwable) { - request.cont.resumeWithException(cause) - } - } - state = FunctionInstanceState.Idle - } - } - } - - /** - * Stop the function instance. - */ - private fun stop() { - val job = job - - if (job != null) { - this.job = null - job.cancel() - } - } - } - - override fun close() { - scope.cancel() - } - - /** - * A function invocation request. - */ - private data class InvocationRequest(val cont: Continuation) -} diff --git a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/delay/ColdStartModel.kt b/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/delay/ColdStartModel.kt deleted file mode 100644 index f5035ca2..00000000 --- a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/delay/ColdStartModel.kt +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2021 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.faas.simulator.delay - -/** - * Model parameters for the cold start times of serverless services. - */ -public enum class ColdStartModel { - // Min and max memory values from [Peeking Behind The Curtains of Serverless Platforms][2018], - // other values deduced from linear curve. - LAMBDA { - override fun coldStartParam(provisionedMemory: Int): Pair { - return when (provisionedMemory) { - 128 -> Pair(265.21, 354.43) - 256 -> Pair(261.46, 334.23) - 512 -> Pair(257.71, 314.03) - 1024 -> Pair(253.96, 293.83) - 1536 -> Pair(250.07, 273.63) - 2048 -> Pair(246.11, 253.43) - else -> Pair(0.0, 1.0) - } - } - }, - AZURE { - // Azure by default uses 1.5gb memory to instantiate functions - override fun coldStartParam(provisionedMemory: Int): Pair { - return Pair(242.66, 340.67) - } - }, - - GOOGLE { - override fun coldStartParam(provisionedMemory: Int): Pair { - return when (provisionedMemory) { - 128 -> Pair(493.04, 345.8) - 256 -> Pair(416.59, 301.5) - 512 -> Pair(340.14, 257.2) - 1024 -> Pair(263.69, 212.9) - 1536 -> Pair(187.24, 168.6) - 2048 -> Pair(110.77, 124.3) - else -> Pair(0.0, 1.0) - } - } - }, ; - - /** - * Obtain the stochastic parameters for the cold start models. - */ - public abstract fun coldStartParam(provisionedMemory: Int): Pair -} diff --git a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/delay/DelayInjector.kt b/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/delay/DelayInjector.kt deleted file mode 100644 index c1df682c..00000000 --- a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/delay/DelayInjector.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2021 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.faas.simulator.delay - -import org.opendc.faas.service.deployer.FunctionInstance - -/** - * An interface for modeling the delay caused by function cold starts. - */ -public interface DelayInjector { - /** - * Returns the cold start delay duration sampled from a normal distribution, the distribution is - * initialized using custom mean and standard deviation based on provisioned memory, language and - * failure model - */ - public fun getColdStartDelay(instance: FunctionInstance): Long -} diff --git a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/delay/StochasticDelayInjector.kt b/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/delay/StochasticDelayInjector.kt deleted file mode 100644 index de7b4aa5..00000000 --- a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/delay/StochasticDelayInjector.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2021 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.faas.simulator.delay - -import org.opendc.faas.service.deployer.FunctionInstance -import java.util.random.RandomGenerator -import kotlin.math.abs - -/* - * Interface for instance deployment delay estimation. - */ -public class StochasticDelayInjector(private val model: ColdStartModel, private val random: RandomGenerator) : DelayInjector { - override fun getColdStartDelay(instance: FunctionInstance): Long { - val (mean, sd) = model.coldStartParam(instance.function.memorySize.toInt()) - return abs(random.nextGaussian() * sd + mean).toLong() - } -} diff --git a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/delay/ZeroDelayInjector.kt b/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/delay/ZeroDelayInjector.kt deleted file mode 100644 index 0e318764..00000000 --- a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/delay/ZeroDelayInjector.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2021 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.faas.simulator.delay - -import org.opendc.faas.service.deployer.FunctionInstance - -public object ZeroDelayInjector : DelayInjector { - override fun getColdStartDelay(instance: FunctionInstance): Long = 0 -} diff --git a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/workload/SimFaaSWorkload.kt b/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/workload/SimFaaSWorkload.kt deleted file mode 100644 index aaee26c0..00000000 --- a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/workload/SimFaaSWorkload.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2021 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.faas.simulator.workload - -import org.opendc.simulator.compute.workload.SimWorkload - -/** - * A model for a serverless function workload, which may be invoked multiple times. - */ -public interface SimFaaSWorkload : SimWorkload { - /** - * This method is invoked when an active function instance is invoked. - */ - public suspend fun invoke() -} diff --git a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/workload/SimFaaSWorkloadMapper.kt b/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/workload/SimFaaSWorkloadMapper.kt deleted file mode 100644 index b22dd659..00000000 --- a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/workload/SimFaaSWorkloadMapper.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2021 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.faas.simulator.workload - -import org.opendc.faas.api.FaaSFunction -import org.opendc.faas.service.FunctionObject - -/** - * A [SimFaaSWorkloadMapper] is responsible for mapping a [FaaSFunction] to a [SimFaaSWorkload] that - * can be simulated. - */ -public fun interface SimFaaSWorkloadMapper { - /** - * Map the specified [function] to a [SimFaaSWorkload] that can be simulated. - */ - public fun createWorkload(function: FunctionObject): SimFaaSWorkload -} diff --git a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/workload/SimMetaFaaSWorkloadMapper.kt b/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/workload/SimMetaFaaSWorkloadMapper.kt deleted file mode 100644 index 8da8bd19..00000000 --- a/opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/workload/SimMetaFaaSWorkloadMapper.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2021 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.faas.simulator.workload - -import org.opendc.faas.service.FunctionObject - -/** - * A [SimFaaSWorkloadMapper] that maps a [FunctionObject] to a workload via the meta-data. - */ -public class SimMetaFaaSWorkloadMapper(private val key: String = "workload") : SimFaaSWorkloadMapper { - override fun createWorkload(function: FunctionObject): SimFaaSWorkload { - return requireNotNull(function.meta[key]) as SimFaaSWorkload - } -} diff --git a/opendc-faas/opendc-faas-simulator/src/test/kotlin/org/opendc/faas/simulator/SimFaaSServiceTest.kt b/opendc-faas/opendc-faas-simulator/src/test/kotlin/org/opendc/faas/simulator/SimFaaSServiceTest.kt deleted file mode 100644 index 2d6d4ac8..00000000 --- a/opendc-faas/opendc-faas-simulator/src/test/kotlin/org/opendc/faas/simulator/SimFaaSServiceTest.kt +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2021 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.faas.simulator - -import io.mockk.coVerify -import io.mockk.spyk -import kotlinx.coroutines.delay -import kotlinx.coroutines.yield -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertAll -import org.opendc.faas.service.FaaSService -import org.opendc.faas.service.autoscaler.FunctionTerminationPolicyFixed -import org.opendc.faas.service.router.RandomRoutingPolicy -import org.opendc.faas.simulator.delay.ColdStartModel -import org.opendc.faas.simulator.delay.StochasticDelayInjector -import org.opendc.faas.simulator.workload.SimFaaSWorkload -import org.opendc.simulator.compute.model.Cpu -import org.opendc.simulator.compute.model.MachineModel -import org.opendc.simulator.compute.model.MemoryUnit -import org.opendc.simulator.compute.workload.SimWorkload -import org.opendc.simulator.compute.workload.SimWorkloads -import org.opendc.simulator.kotlin.runSimulation -import java.time.Duration -import java.util.Random - -/** - * A test suite for the [FaaSService] implementation under simulated conditions. - */ -internal class SimFaaSServiceTest { - private lateinit var machineModel: MachineModel - - @BeforeEach - fun setUp() { - machineModel = - MachineModel( - Cpu( - 0, - 2, - 1000.0, - "Intel", - "Xeon", - "amd64", - ), - MemoryUnit("Crucial", "MTA18ASF4G72AZ-3G2B1", 3200.0, 32_000 * 4), - ) - } - - @Test - fun testSmoke() = - runSimulation { - val random = Random(0) - val workload = - spyk( - object : SimFaaSWorkload, SimWorkload by SimWorkloads.runtime(1000, 1.0) { - override suspend fun invoke() { - delay(random.nextInt(1000).toLong()) - } - }, - ) - - val delayInjector = StochasticDelayInjector(ColdStartModel.GOOGLE, random) - val deployer = SimFunctionDeployer(dispatcher, machineModel, delayInjector) { workload } - val service = - FaaSService( - dispatcher, - deployer, - RandomRoutingPolicy(), - FunctionTerminationPolicyFixed(dispatcher, timeout = Duration.ofMillis(10000)), - ) - - val client = service.newClient() - - val function = client.newFunction("test", 128) - function.invoke() - delay(2000) - - service.close() - deployer.close() - - yield() - - val funcStats = service.getFunctionStats(function) - - // fixme: waitTime is probably wrong, and should be 100 - assertAll( - { coVerify { workload.invoke() } }, - { assertEquals(1, funcStats.totalInvocations) }, - { assertEquals(1, funcStats.delayedInvocations) }, - { assertEquals(0, funcStats.failedInvocations) }, - { assertEquals(0.0, funcStats.waitTime.mean) }, - { assertEquals(1285.0, funcStats.activeTime.mean) }, - ) - } -} -- cgit v1.2.3