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/README.md | 7 - opendc-faas/build.gradle.kts | 27 -- opendc-faas/opendc-faas-api/build.gradle.kts | 28 -- .../main/kotlin/org/opendc/faas/api/FaaSClient.kt | 74 ------ .../kotlin/org/opendc/faas/api/FaaSFunction.kt | 70 ----- opendc-faas/opendc-faas-service/build.gradle.kts | 39 --- .../kotlin/org/opendc/faas/service/FaaSService.kt | 80 ------ .../org/opendc/faas/service/FunctionObject.kt | 145 ----------- .../autoscaler/FunctionTerminationPolicy.kt | 36 --- .../autoscaler/FunctionTerminationPolicyFixed.kt | 67 ----- .../autoscaler/FunctionTerminationPolicyNull.kt | 34 --- .../faas/service/deployer/FunctionDeployer.kt | 46 ---- .../faas/service/deployer/FunctionInstance.kt | 55 ---- .../service/deployer/FunctionInstanceListener.kt | 36 --- .../faas/service/deployer/FunctionInstanceState.kt | 48 ---- .../faas/service/internal/FaaSFunctionImpl.kt | 70 ----- .../faas/service/internal/FaaSServiceImpl.kt | 290 --------------------- .../faas/service/router/RandomRoutingPolicy.kt | 41 --- .../opendc/faas/service/router/RoutingPolicy.kt | 39 --- .../opendc/faas/service/telemetry/FunctionStats.kt | 48 ---- .../faas/service/telemetry/SchedulerStats.kt | 36 --- .../org/opendc/faas/service/FaaSServiceTest.kt | 185 ------------- 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 --------- 32 files changed, 2128 deletions(-) delete mode 100644 opendc-faas/README.md delete mode 100644 opendc-faas/build.gradle.kts delete mode 100644 opendc-faas/opendc-faas-api/build.gradle.kts delete mode 100644 opendc-faas/opendc-faas-api/src/main/kotlin/org/opendc/faas/api/FaaSClient.kt delete mode 100644 opendc-faas/opendc-faas-api/src/main/kotlin/org/opendc/faas/api/FaaSFunction.kt delete mode 100644 opendc-faas/opendc-faas-service/build.gradle.kts delete mode 100644 opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/FaaSService.kt delete mode 100644 opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/FunctionObject.kt delete mode 100644 opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/autoscaler/FunctionTerminationPolicy.kt delete mode 100644 opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/autoscaler/FunctionTerminationPolicyFixed.kt delete mode 100644 opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/autoscaler/FunctionTerminationPolicyNull.kt delete mode 100644 opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/deployer/FunctionDeployer.kt delete mode 100644 opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/deployer/FunctionInstance.kt delete mode 100644 opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/deployer/FunctionInstanceListener.kt delete mode 100644 opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/deployer/FunctionInstanceState.kt delete mode 100644 opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/internal/FaaSFunctionImpl.kt delete mode 100644 opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/internal/FaaSServiceImpl.kt delete mode 100644 opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/router/RandomRoutingPolicy.kt delete mode 100644 opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/router/RoutingPolicy.kt delete mode 100644 opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/telemetry/FunctionStats.kt delete mode 100644 opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/telemetry/SchedulerStats.kt delete mode 100644 opendc-faas/opendc-faas-service/src/test/kotlin/org/opendc/faas/service/FaaSServiceTest.kt 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') diff --git a/opendc-faas/README.md b/opendc-faas/README.md deleted file mode 100644 index fe6e5b80..00000000 --- a/opendc-faas/README.md +++ /dev/null @@ -1,7 +0,0 @@ -OpenDC FaaS -================= - -This module contains a reproduction of Soufiane Jounaid's BSc Computer Science thesis: -OpenDC Serverless: Design, Implementation and Evaluation of a FaaS Platform Simulator [1] - -[1] https://drive.google.com/file/d/12hox3PwagpD0jNFA57tO4r2HqvOonkY3/view?usp=sharing diff --git a/opendc-faas/build.gradle.kts b/opendc-faas/build.gradle.kts deleted file mode 100644 index 002582bb..00000000 --- a/opendc-faas/build.gradle.kts +++ /dev/null @@ -1,27 +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 = "Function-as-a-Service (FaaS) platform for OpenDC" - -subprojects { - group = "org.opendc.faas" -} diff --git a/opendc-faas/opendc-faas-api/build.gradle.kts b/opendc-faas/opendc-faas-api/build.gradle.kts deleted file mode 100644 index 2e4b5776..00000000 --- a/opendc-faas/opendc-faas-api/build.gradle.kts +++ /dev/null @@ -1,28 +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 = "API for the OpenDC FaaS platform" - -// Build configuration -plugins { - `kotlin-library-conventions` -} diff --git a/opendc-faas/opendc-faas-api/src/main/kotlin/org/opendc/faas/api/FaaSClient.kt b/opendc-faas/opendc-faas-api/src/main/kotlin/org/opendc/faas/api/FaaSClient.kt deleted file mode 100644 index 297d3065..00000000 --- a/opendc-faas/opendc-faas-api/src/main/kotlin/org/opendc/faas/api/FaaSClient.kt +++ /dev/null @@ -1,74 +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.api - -import java.util.UUID - -/** - * Client interface to the OpenDC FaaS platform. - */ -public interface FaaSClient : AutoCloseable { - /** - * Obtain the list of [FaaSFunction]s accessible by the requesting user. - */ - public suspend fun queryFunctions(): List - - /** - * Obtain a [FaaSFunction] by its unique identifier. - * - * @param id The identifier of the flavor. - */ - public suspend fun findFunction(id: UUID): FaaSFunction? - - /** - * Obtain a [FaaSFunction] by its name. - * - * @param name The name of the function. - */ - public suspend fun findFunction(name: String): FaaSFunction? - - /** - * Create a new serverless function. - * - * @param name The name of the function. - * @param memorySize The memory allocated for the function in MB. - * @param labels The labels associated with the function. - * @param meta The metadata associated with the function. - */ - public suspend fun newFunction( - name: String, - memorySize: Long, - labels: Map = emptyMap(), - meta: Map = emptyMap(), - ): FaaSFunction - - /** - * Invoke the function with the specified [name]. - */ - public suspend fun invoke(name: String) - - /** - * Release the resources associated with this client, preventing any further API calls. - */ - public override fun close() -} diff --git a/opendc-faas/opendc-faas-api/src/main/kotlin/org/opendc/faas/api/FaaSFunction.kt b/opendc-faas/opendc-faas-api/src/main/kotlin/org/opendc/faas/api/FaaSFunction.kt deleted file mode 100644 index 40f0092f..00000000 --- a/opendc-faas/opendc-faas-api/src/main/kotlin/org/opendc/faas/api/FaaSFunction.kt +++ /dev/null @@ -1,70 +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.api - -import java.util.UUID - -/** - * A serverless function instance. - */ -public interface FaaSFunction { - /** - * The unique identifier of the function. - */ - public val uid: UUID - - /** - * The name of the function. - */ - public val name: String - - /** - * The amount of memory allocated for this function in MB. - */ - public val memorySize: Long - - /** - * The identifying labels attached to the resource. - */ - public val labels: Map - - /** - * The non-identifying metadata attached to the resource. - */ - public val meta: Map - - /** - * Invoke the serverless function. - */ - public suspend operator fun invoke() - - /** - * Request the function to be deleted. - */ - public suspend fun delete() - - /** - * Refresh the local state of this object. - */ - public suspend fun refresh() -} diff --git a/opendc-faas/opendc-faas-service/build.gradle.kts b/opendc-faas/opendc-faas-service/build.gradle.kts deleted file mode 100644 index 90cb8f56..00000000 --- a/opendc-faas/opendc-faas-service/build.gradle.kts +++ /dev/null @@ -1,39 +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 = "FaaS service for OpenDC" - -// Build configuration -plugins { - `kotlin-library-conventions` -} - -dependencies { - api(projects.opendcFaas.opendcFaasApi) - api(libs.commons.math3) - implementation(projects.opendcCommon) - implementation(libs.kotlin.logging) - - testImplementation(projects.opendcSimulator.opendcSimulatorCore) - testRuntimeOnly(libs.log4j.core) - testRuntimeOnly(libs.log4j.slf4j) -} diff --git a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/FaaSService.kt b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/FaaSService.kt deleted file mode 100644 index e9634ccc..00000000 --- a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/FaaSService.kt +++ /dev/null @@ -1,80 +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.service - -import org.opendc.common.Dispatcher -import org.opendc.faas.api.FaaSClient -import org.opendc.faas.api.FaaSFunction -import org.opendc.faas.service.autoscaler.FunctionTerminationPolicy -import org.opendc.faas.service.deployer.FunctionDeployer -import org.opendc.faas.service.internal.FaaSServiceImpl -import org.opendc.faas.service.router.RoutingPolicy -import org.opendc.faas.service.telemetry.FunctionStats -import org.opendc.faas.service.telemetry.SchedulerStats -import java.time.Duration - -/** - * The [FaaSService] hosts the service implementation of the OpenDC FaaS platform. - */ -public interface FaaSService : AutoCloseable { - /** - * Create a new [FaaSClient] to control the compute service. - */ - public fun newClient(): FaaSClient - - /** - * Collect statistics about the scheduler of the service. - */ - public fun getSchedulerStats(): SchedulerStats - - /** - * Collect statistics about the specified [function]. - */ - public fun getFunctionStats(function: FaaSFunction): FunctionStats - - /** - * Terminate the lifecycle of the FaaS service, stopping all running function instances. - */ - public override fun close() - - public companion object { - /** - * Construct a new [FaaSService] implementation. - * - * @param dispatcher The [Dispatcher] used for scheduling events. - * @param deployer the [FunctionDeployer] to use for deploying function instances. - * @param routingPolicy The policy to route function invocations. - * @param terminationPolicy The policy for terminating function instances. - * @param quantum The scheduling quantum of the service (100 ms default) - */ - public operator fun invoke( - dispatcher: Dispatcher, - deployer: FunctionDeployer, - routingPolicy: RoutingPolicy, - terminationPolicy: FunctionTerminationPolicy, - quantum: Duration = Duration.ofMillis(100), - ): FaaSService { - return FaaSServiceImpl(dispatcher, deployer, routingPolicy, terminationPolicy, quantum) - } - } -} diff --git a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/FunctionObject.kt b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/FunctionObject.kt deleted file mode 100644 index 0ed96b96..00000000 --- a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/FunctionObject.kt +++ /dev/null @@ -1,145 +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.service - -import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics -import org.opendc.faas.service.deployer.FunctionInstance -import org.opendc.faas.service.telemetry.FunctionStats -import java.util.UUID - -/** - * An [FunctionObject] represents the service's view of a serverless function. - */ -public class FunctionObject( - public val uid: UUID, - name: String, - allocatedMemory: Long, - labels: Map, - meta: Map, -) : AutoCloseable { - /** - * Metrics tracked per function. - */ - private var localInvocations = 0L - private var localTimelyInvocations = 0L - private var localDelayedInvocations = 0L - private var localFailedInvocations = 0L - private var localActiveInstances = 0 - private var localIdleInstances = 0 - private val localWaitTime = - DescriptiveStatistics() - .apply { windowSize = 100 } - private val localActiveTime = - DescriptiveStatistics() - .apply { windowSize = 100 } - - /** - * The instances associated with this function. - */ - public val instances: MutableList = mutableListOf() - - public var name: String = name - private set - - public var memorySize: Long = allocatedMemory - private set - - public val labels: MutableMap = labels.toMutableMap() - - public val meta: MutableMap = meta.toMutableMap() - - /** - * Report a scheduled invocation. - */ - internal fun reportSubmission() { - localInvocations++ - } - - /** - * Report the deployment of an invocation. - */ - internal fun reportDeployment(isDelayed: Boolean) { - if (isDelayed) { - localDelayedInvocations++ - localIdleInstances++ - } else { - localTimelyInvocations++ - } - } - - /** - * Report the start of a function invocation. - */ - internal fun reportStart( - start: Long, - submitTime: Long, - ) { - val wait = start - submitTime - localWaitTime.addValue(wait.toDouble()) - - localIdleInstances-- - localActiveInstances++ - } - - /** - * Report the failure of a function invocation. - */ - internal fun reportFailure() { - localFailedInvocations++ - } - - /** - * Report the end of a function invocation. - */ - internal fun reportEnd(duration: Long) { - localActiveTime.addValue(duration.toDouble()) - localIdleInstances++ - localActiveInstances-- - } - - /** - * Collect the statistics of this function. - */ - internal fun getStats(): FunctionStats { - return FunctionStats( - localInvocations, - localTimelyInvocations, - localDelayedInvocations, - localFailedInvocations, - localActiveInstances, - localIdleInstances, - localWaitTime.copy(), - localActiveTime.copy(), - ) - } - - override fun close() { - val copy = instances.toList() // Make copy to prevent concurrent modification - copy.forEach(FunctionInstance::close) - instances.clear() - } - - override fun equals(other: Any?): Boolean = other is FunctionObject && uid == other.uid - - override fun hashCode(): Int = uid.hashCode() -} diff --git a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/autoscaler/FunctionTerminationPolicy.kt b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/autoscaler/FunctionTerminationPolicy.kt deleted file mode 100644 index 2ab3638b..00000000 --- a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/autoscaler/FunctionTerminationPolicy.kt +++ /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. - */ - -package org.opendc.faas.service.autoscaler - -import org.opendc.faas.service.deployer.FunctionInstance -import org.opendc.faas.service.deployer.FunctionInstanceListener - -/** - * A management policy that is responsible for downscaling the active function instances for a function. - */ -public interface FunctionTerminationPolicy : FunctionInstanceListener { - /** - * Enqueue the specified [instance] to be scheduled for termination a - */ - public fun enqueue(instance: FunctionInstance) -} diff --git a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/autoscaler/FunctionTerminationPolicyFixed.kt b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/autoscaler/FunctionTerminationPolicyFixed.kt deleted file mode 100644 index 9edb8c1d..00000000 --- a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/autoscaler/FunctionTerminationPolicyFixed.kt +++ /dev/null @@ -1,67 +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.service.autoscaler - -import org.opendc.common.Dispatcher -import org.opendc.common.util.TimerScheduler -import org.opendc.faas.service.deployer.FunctionInstance -import org.opendc.faas.service.deployer.FunctionInstanceState -import java.time.Duration - -/** - * A [FunctionTerminationPolicy] that terminates idle function instances after a fixed keep-alive time. - * - * @param timeout The idle timeout after which the function instance is terminated. - */ -public class FunctionTerminationPolicyFixed( - dispatcher: Dispatcher, - public val timeout: Duration, -) : FunctionTerminationPolicy { - /** - * The [TimerScheduler] used to schedule the function terminations. - */ - private val scheduler = TimerScheduler(dispatcher) - - override fun enqueue(instance: FunctionInstance) { - // Cancel the existing timeout timer - scheduler.cancel(instance) - } - - override fun onStateChanged( - instance: FunctionInstance, - newState: FunctionInstanceState, - ) { - when (newState) { - FunctionInstanceState.Active -> scheduler.cancel(instance) - FunctionInstanceState.Idle -> schedule(instance) - else -> {} - } - } - - /** - * Schedule termination for the specified [instance]. - */ - private fun schedule(instance: FunctionInstance) { - scheduler.startSingleTimer(instance, timeout.toMillis()) { instance.close() } - } -} diff --git a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/autoscaler/FunctionTerminationPolicyNull.kt b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/autoscaler/FunctionTerminationPolicyNull.kt deleted file mode 100644 index 957e569b..00000000 --- a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/autoscaler/FunctionTerminationPolicyNull.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.service.autoscaler - -import org.opendc.faas.service.deployer.FunctionInstance - -/** - * A [FunctionTerminationPolicy] that never terminates function instances. - */ -public class FunctionTerminationPolicyNull : FunctionTerminationPolicy { - override fun enqueue(instance: FunctionInstance) { - // No-op - } -} diff --git a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/deployer/FunctionDeployer.kt b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/deployer/FunctionDeployer.kt deleted file mode 100644 index 13d48fbf..00000000 --- a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/deployer/FunctionDeployer.kt +++ /dev/null @@ -1,46 +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.service.deployer - -import org.opendc.faas.service.FunctionObject - -/** - * A [FunctionDeployer] is responsible for ensuring that an instance of an arbitrary function, a [FunctionInstance], - * is deployed. - * - * The function deployer should combine the configuration stored in the function registry, the parameters supplied by - * the requester, and other factors into a decision of how the function should be deployed, including how many and - * what kind of resources it should receive. - * - * Though it decides how the function instance should be deployed, the deployment of the function instance itself is - * delegated to the Resource Orchestration Layer. - */ -public interface FunctionDeployer { - /** - * Deploy the specified [function]. - */ - public fun deploy( - function: FunctionObject, - listener: FunctionInstanceListener, - ): FunctionInstance -} diff --git a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/deployer/FunctionInstance.kt b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/deployer/FunctionInstance.kt deleted file mode 100644 index 77eadbbe..00000000 --- a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/deployer/FunctionInstance.kt +++ /dev/null @@ -1,55 +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.service.deployer - -import org.opendc.faas.service.FunctionObject - -/** - * A [FunctionInstance] is a self-contained worker—typically a container—capable of handling function executions. - * - * Multiple, concurrent function instances can exist for a single function, for scalability purposes. - */ -public interface FunctionInstance : AutoCloseable { - /** - * The state of the instance. - */ - public val state: FunctionInstanceState - - /** - * The [FunctionObject] that is represented by this instance. - */ - public val function: FunctionObject - - /** - * Invoke the function instance. - * - * This method will suspend execution util the function instance has returned. - */ - public suspend fun invoke() - - /** - * Indicate to the resource manager that the instance is not needed anymore and may be cleaned up by the resource - * manager. - */ - public override fun close() -} diff --git a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/deployer/FunctionInstanceListener.kt b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/deployer/FunctionInstanceListener.kt deleted file mode 100644 index e88b7104..00000000 --- a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/deployer/FunctionInstanceListener.kt +++ /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. - */ - -package org.opendc.faas.service.deployer - -/** - * Listener interface for events originating from a [FunctionInstance]. - */ -public interface FunctionInstanceListener { - /** - * This method is invoked when the state of a [FunctionInstance] has changed. - */ - public fun onStateChanged( - instance: FunctionInstance, - newState: FunctionInstanceState, - ) {} -} diff --git a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/deployer/FunctionInstanceState.kt b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/deployer/FunctionInstanceState.kt deleted file mode 100644 index 0c310e6b..00000000 --- a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/deployer/FunctionInstanceState.kt +++ /dev/null @@ -1,48 +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.service.deployer - -/** - * This enumeration describes the states of a [FunctionInstance]. - */ -public enum class FunctionInstanceState { - /** - * The function instance is currently being provisioned. - */ - Provisioning, - - /** - * The function instance is idle and ready to execute. - */ - Idle, - - /** - * The function instance is executing. - */ - Active, - - /** - * The function instance is released and cannot be used anymore. - */ - Deleted, -} diff --git a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/internal/FaaSFunctionImpl.kt b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/internal/FaaSFunctionImpl.kt deleted file mode 100644 index 7cc85e40..00000000 --- a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/internal/FaaSFunctionImpl.kt +++ /dev/null @@ -1,70 +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.service.internal - -import org.opendc.faas.api.FaaSFunction -import org.opendc.faas.service.FunctionObject -import java.util.UUID - -/** - * A [FaaSFunction] implementation that is passed to clients. - */ -internal class FaaSFunctionImpl( - private val service: FaaSServiceImpl, - private val state: FunctionObject, -) : FaaSFunction { - override val uid: UUID = state.uid - - override var name: String = state.name - private set - - override var memorySize: Long = state.memorySize - private set - - override var labels: Map = state.labels.toMap() - private set - - override var meta: Map = state.meta.toMap() - private set - - override suspend fun delete() { - service.delete(state) - } - - override suspend fun invoke() { - service.invoke(state) - } - - override suspend fun refresh() { - name = state.name - memorySize = state.memorySize - labels = state.labels - meta = state.meta - } - - override fun equals(other: Any?): Boolean = other is FaaSFunctionImpl && uid == other.uid - - override fun hashCode(): Int = uid.hashCode() - - override fun toString(): String = "FaaSFunction[uid=$uid,name=$name]" -} diff --git a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/internal/FaaSServiceImpl.kt b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/internal/FaaSServiceImpl.kt deleted file mode 100644 index 397b0e7d..00000000 --- a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/internal/FaaSServiceImpl.kt +++ /dev/null @@ -1,290 +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.service.internal - -import kotlinx.coroutines.InternalCoroutinesApi -import kotlinx.coroutines.intrinsics.startCoroutineCancellable -import kotlinx.coroutines.suspendCancellableCoroutine -import mu.KotlinLogging -import org.opendc.common.Dispatcher -import org.opendc.common.util.Pacer -import org.opendc.faas.api.FaaSClient -import org.opendc.faas.api.FaaSFunction -import org.opendc.faas.service.FaaSService -import org.opendc.faas.service.FunctionObject -import org.opendc.faas.service.autoscaler.FunctionTerminationPolicy -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.service.router.RoutingPolicy -import org.opendc.faas.service.telemetry.FunctionStats -import org.opendc.faas.service.telemetry.SchedulerStats -import java.lang.IllegalStateException -import java.time.Duration -import java.time.InstantSource -import java.util.ArrayDeque -import java.util.Random -import java.util.UUID -import kotlin.coroutines.Continuation -import kotlin.coroutines.resumeWithException - -/** - * Implementation of the [FaaSService] interface. - * - * This component acts as the function router from the SPEC RG Reference Architecture for FaaS and is responsible - * for routing incoming requests or events to the correct [FunctionInstance]. If no [FunctionInstance] is available, - * this component queues the events to await the deployment of new instances. - */ -internal class FaaSServiceImpl( - dispatcher: Dispatcher, - private val deployer: FunctionDeployer, - private val routingPolicy: RoutingPolicy, - private val terminationPolicy: FunctionTerminationPolicy, - quantum: Duration, -) : FaaSService, FunctionInstanceListener { - /** - * The logger instance of this server. - */ - private val logger = KotlinLogging.logger {} - - /** - * The [Pacer] to use for scheduling the scheduler cycles. - */ - private val pacer = Pacer(dispatcher, quantum.toMillis()) { doSchedule() } - - /** - * The [InstantSource] instance representing the clock. - */ - private val clock = dispatcher.timeSource - - /** - * The [Random] instance used to generate unique identifiers for the objects. - */ - private val random = Random(0) - - /** - * The registered functions for this service. - */ - private val functions = mutableMapOf() - private val functionsByName = mutableMapOf() - - /** - * The queue of invocation requests. - */ - private val queue = ArrayDeque() - - /** - * Metrics tracked by the service. - */ - private var totalInvocations = 0L - private var timelyInvocations = 0L - private var delayedInvocations = 0L - - override fun newClient(): FaaSClient { - return object : FaaSClient { - private var isClosed: Boolean = false - - /** - * Exposes a [FunctionObject] to a client-exposed [FaaSFunction] instance. - */ - private fun FunctionObject.asClientFunction(): FaaSFunction { - return FaaSFunctionImpl(this@FaaSServiceImpl, this) - } - - override suspend fun queryFunctions(): List { - check(!isClosed) { "Client is already closed" } - - return functions.values.map { it.asClientFunction() } - } - - override suspend fun findFunction(id: UUID): FaaSFunction? { - check(!isClosed) { "Client is already closed" } - - return functions[id]?.asClientFunction() - } - - override suspend fun findFunction(name: String): FaaSFunction? { - check(!isClosed) { "Client is already closed" } - - return functionsByName[name]?.asClientFunction() - } - - override suspend fun newFunction( - name: String, - memorySize: Long, - labels: Map, - meta: Map, - ): FaaSFunction { - check(!isClosed) { "Client is already closed" } - require(name !in functionsByName) { "Function with same name exists" } - - val uid = UUID(clock.millis(), random.nextLong()) - val function = - FunctionObject( - uid, - name, - memorySize, - labels, - meta, - ) - - functionsByName[name] = function - functions[uid] = function - - return function.asClientFunction() - } - - override suspend fun invoke(name: String) { - check(!isClosed) { "Client is already closed" } - - val func = requireNotNull(functionsByName[name]) { "Unknown function" } - this@FaaSServiceImpl.invoke(func) - } - - override fun close() { - isClosed = true - } - } - } - - override fun getSchedulerStats(): SchedulerStats { - return SchedulerStats(totalInvocations, timelyInvocations, delayedInvocations) - } - - override fun getFunctionStats(function: FaaSFunction): FunctionStats { - val func = requireNotNull(functions[function.uid]) { "Unknown function" } - return func.getStats() - } - - /** - * Indicate that a new scheduling cycle is needed due to a change to the service's state. - */ - private fun schedule() { - // Bail out in case the queue is empty. - if (queue.isEmpty()) { - return - } - - pacer.enqueue() - } - - /** - * Run a single scheduling iteration. - */ - @OptIn(InternalCoroutinesApi::class) - private fun doSchedule() { - try { - while (queue.isNotEmpty()) { - val (submitTime, function, cont) = queue.poll() - - val instances = function.instances - - // Check if there exists an instance of the function - val activeInstance = - if (instances.isNotEmpty()) { - routingPolicy.select(instances, function) - } else { - null - } - - val instance = - if (activeInstance != null) { - timelyInvocations++ - function.reportDeployment(isDelayed = false) - - activeInstance - } else { - val instance = deployer.deploy(function, this) - instances.add(instance) - terminationPolicy.enqueue(instance) - - delayedInvocations++ - function.reportDeployment(isDelayed = true) - - instance - } - - suspend { - val start = clock.millis() - function.reportStart(start, submitTime) - try { - instance.invoke() - } catch (e: Throwable) { - logger.debug(e) { "Function invocation failed" } - function.reportFailure() - } finally { - val end = clock.millis() - function.reportEnd(end - start) - } - }.startCoroutineCancellable(cont) - } - } catch (cause: Throwable) { - logger.error(cause) { "Exception occurred during scheduling cycle" } - } - } - - suspend fun invoke(function: FunctionObject) { - check(function.uid in functions) { "Function does not exist (anymore)" } - - totalInvocations++ - function.reportSubmission() - - return suspendCancellableCoroutine { cont -> - if (!queue.add(InvocationRequest(clock.millis(), function, cont))) { - cont.resumeWithException(IllegalStateException("Failed to enqueue request")) - } else { - schedule() - } - } - } - - fun delete(function: FunctionObject) { - functions.remove(function.uid) - functionsByName.remove(function.name) - } - - override fun close() { - // Stop all function instances - for ((_, function) in functions) { - function.close() - } - } - - override fun onStateChanged( - instance: FunctionInstance, - newState: FunctionInstanceState, - ) { - terminationPolicy.onStateChanged(instance, newState) - - if (newState == FunctionInstanceState.Deleted) { - val function = instance.function - function.instances.remove(instance) - } - } - - /** - * A request to invoke a function. - */ - private data class InvocationRequest(val timestamp: Long, val function: FunctionObject, val cont: Continuation) -} diff --git a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/router/RandomRoutingPolicy.kt b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/router/RandomRoutingPolicy.kt deleted file mode 100644 index 1eb03e5a..00000000 --- a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/router/RandomRoutingPolicy.kt +++ /dev/null @@ -1,41 +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.service.router - -import org.opendc.faas.service.FunctionObject -import org.opendc.faas.service.deployer.FunctionInstance -import java.util.SplittableRandom -import java.util.random.RandomGenerator - -/** - * A [RoutingPolicy] that selects a random function instance. - */ -public class RandomRoutingPolicy(private val random: RandomGenerator = SplittableRandom(0)) : RoutingPolicy { - override fun select( - instances: List, - function: FunctionObject, - ): FunctionInstance { - val idx = random.nextInt(instances.size) - return instances.elementAt(idx) - } -} diff --git a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/router/RoutingPolicy.kt b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/router/RoutingPolicy.kt deleted file mode 100644 index c8ea37fc..00000000 --- a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/router/RoutingPolicy.kt +++ /dev/null @@ -1,39 +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.service.router - -import org.opendc.faas.service.FunctionObject -import org.opendc.faas.service.deployer.FunctionInstance - -/** - * A [RoutingPolicy] decides to which [FunctionInstance] a function invocation should be routed. - */ -public interface RoutingPolicy { - /** - * Select the instance to which the request should be routed to. - */ - public fun select( - instances: List, - function: FunctionObject, - ): FunctionInstance? -} diff --git a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/telemetry/FunctionStats.kt b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/telemetry/FunctionStats.kt deleted file mode 100644 index db6db6c1..00000000 --- a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/telemetry/FunctionStats.kt +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.faas.service.telemetry - -import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics - -/** - * Statistics about function invocations. - * - * @property totalInvocations The number of function invocations. - * @property timelyInvocations The number of function invocations that could be handled directly. - * @property delayedInvocations The number of function invocations that are delayed (cold starts). - * @property failedInvocations The number of function invocations that failed. - * @property activeInstances The number of active function instances. - * @property idleInstances The number of idle function instances. - * @property waitTime Statistics about the wait time of a function invocation. - * @property activeTime Statistics about the runtime of a function invocation. - */ -public data class FunctionStats( - val totalInvocations: Long, - val timelyInvocations: Long, - val delayedInvocations: Long, - val failedInvocations: Long, - val activeInstances: Int, - val idleInstances: Int, - val waitTime: DescriptiveStatistics, - val activeTime: DescriptiveStatistics, -) diff --git a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/telemetry/SchedulerStats.kt b/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/telemetry/SchedulerStats.kt deleted file mode 100644 index b65dfb03..00000000 --- a/opendc-faas/opendc-faas-service/src/main/kotlin/org/opendc/faas/service/telemetry/SchedulerStats.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.faas.service.telemetry - -/** - * Statistics reported by the FaaS scheduler. - * - * @property totalInvocations The total amount of function invocations received by the scheduler. - * @property timelyInvocations The amount of function invocations that could be handled directly. - * @property delayedInvocations The amount of function invocations that were delayed due to function deployment. - */ -public data class SchedulerStats( - val totalInvocations: Long, - val timelyInvocations: Long, - val delayedInvocations: Long, -) diff --git a/opendc-faas/opendc-faas-service/src/test/kotlin/org/opendc/faas/service/FaaSServiceTest.kt b/opendc-faas/opendc-faas-service/src/test/kotlin/org/opendc/faas/service/FaaSServiceTest.kt deleted file mode 100644 index 72a5f2c8..00000000 --- a/opendc-faas/opendc-faas-service/src/test/kotlin/org/opendc/faas/service/FaaSServiceTest.kt +++ /dev/null @@ -1,185 +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.service - -import io.mockk.every -import io.mockk.mockk -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotNull -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertDoesNotThrow -import org.junit.jupiter.api.assertThrows -import org.opendc.faas.api.FaaSFunction -import org.opendc.faas.service.deployer.FunctionDeployer -import org.opendc.faas.service.deployer.FunctionInstance -import org.opendc.faas.service.deployer.FunctionInstanceState -import org.opendc.simulator.kotlin.runSimulation -import java.util.UUID - -/** - * Test suite for the [FaaSService] implementation. - */ -internal class FaaSServiceTest { - @Test - fun testClientState() = - runSimulation { - val service = FaaSService(dispatcher, mockk(), mockk(), mockk()) - - val client = assertDoesNotThrow { service.newClient() } - assertDoesNotThrow { client.close() } - - assertThrows { client.queryFunctions() } - assertThrows { client.newFunction("test", 128) } - assertThrows { client.invoke("test") } - assertThrows { client.findFunction(UUID.randomUUID()) } - assertThrows { client.findFunction("name") } - } - - @Test - fun testClientInvokeUnknown() = - runSimulation { - val service = FaaSService(dispatcher, mockk(), mockk(), mockk()) - - val client = service.newClient() - - assertThrows { client.invoke("test") } - } - - @Test - fun testClientFunctionCreation() = - runSimulation { - val service = FaaSService(dispatcher, mockk(), mockk(), mockk()) - - val client = service.newClient() - - val function = client.newFunction("test", 128) - - assertEquals("test", function.name) - } - - @Test - fun testClientFunctionQuery() = - runSimulation { - val service = FaaSService(dispatcher, mockk(), mockk(), mockk()) - - val client = service.newClient() - - assertEquals(emptyList(), client.queryFunctions()) - - val function = client.newFunction("test", 128) - - assertEquals(listOf(function), client.queryFunctions()) - } - - @Test - fun testClientFunctionFindById() = - runSimulation { - val service = FaaSService(dispatcher, mockk(), mockk(), mockk()) - - val client = service.newClient() - - assertEquals(emptyList(), client.queryFunctions()) - - val function = client.newFunction("test", 128) - - assertNotNull(client.findFunction(function.uid)) - } - - @Test - fun testClientFunctionFindByName() = - runSimulation { - val service = FaaSService(dispatcher, mockk(), mockk(), mockk()) - - val client = service.newClient() - - assertEquals(emptyList(), client.queryFunctions()) - - val function = client.newFunction("test", 128) - - assertNotNull(client.findFunction(function.name)) - } - - @Test - fun testClientFunctionDuplicateName() = - runSimulation { - val service = FaaSService(dispatcher, mockk(), mockk(), mockk()) - - val client = service.newClient() - - client.newFunction("test", 128) - - assertThrows { client.newFunction("test", 128) } - } - - @Test - fun testClientFunctionDelete() = - runSimulation { - val service = FaaSService(dispatcher, mockk(), mockk(), mockk()) - - val client = service.newClient() - val function = client.newFunction("test", 128) - assertNotNull(client.findFunction(function.uid)) - function.delete() - assertNull(client.findFunction(function.uid)) - - // Delete should be idempotent - function.delete() - } - - @Test - fun testClientFunctionCannotInvokeDeleted() = - runSimulation { - val service = FaaSService(dispatcher, mockk(), mockk(), mockk()) - - val client = service.newClient() - val function = client.newFunction("test", 128) - assertNotNull(client.findFunction(function.uid)) - function.delete() - - assertThrows { function.invoke() } - } - - @Test - fun testClientFunctionInvoke() = - runSimulation { - val deployer = mockk() - val service = FaaSService(dispatcher, deployer, mockk(), mockk(relaxUnitFun = true)) - - every { deployer.deploy(any(), any()) } answers { - object : FunctionInstance { - override val state: FunctionInstanceState = FunctionInstanceState.Idle - override val function: FunctionObject = it.invocation.args[0] as FunctionObject - - override suspend fun invoke() {} - - override fun close() {} - } - } - - val client = service.newClient() - val function = client.newFunction("test", 128) - - function.invoke() - } -} 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