summaryrefslogtreecommitdiff
path: root/opendc-faas/opendc-faas-simulator/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-faas/opendc-faas-simulator/src/main')
-rw-r--r--opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/SimFunctionDeployer.kt69
-rw-r--r--opendc-faas/opendc-faas-simulator/src/main/kotlin/org/opendc/faas/simulator/delay/ColdStartModel.kt2
2 files changed, 38 insertions, 33 deletions
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
index 47b4d4fa..c81dc523 100644
--- 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
@@ -58,14 +58,17 @@ public class SimFunctionDeployer(
private val dispatcher: Dispatcher,
private val model: MachineModel,
private val delayInjector: DelayInjector,
- private val mapper: SimFaaSWorkloadMapper = SimMetaFaaSWorkloadMapper()
+ 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 {
+ override fun deploy(
+ function: FunctionObject,
+ listener: FunctionInstanceListener,
+ ): Instance {
val instance = Instance(function, listener)
instance.start()
return instance
@@ -84,10 +87,11 @@ public class SimFunctionDeployer(
/**
* The machine that will execute the workloads.
*/
- public val machine: SimMachine = SimBareMetalMachine.create(
- FlowEngine.create(dispatcher).newGraph(),
- model
- )
+ public val machine: SimMachine =
+ SimBareMetalMachine.create(
+ FlowEngine.create(dispatcher).newGraph(),
+ model,
+ )
/**
* The job associated with the lifecycle of the instance.
@@ -134,38 +138,39 @@ public class SimFunctionDeployer(
*/
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
- }
- }
+ job =
+ scope.launch {
+ delay(delayInjector.getColdStartDelay(this@Instance))
- while (isActive) {
- if (queue.isEmpty()) {
- chan.receive()
+ launch {
+ try {
+ machine.runWorkload(workload)
+ } finally {
+ state = FunctionInstanceState.Deleted
+ }
}
- 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)
+ 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
}
- state = FunctionInstanceState.Idle
}
- }
}
/**
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
index 624067be..f5035ca2 100644
--- 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
@@ -60,7 +60,7 @@ public enum class ColdStartModel {
else -> Pair(0.0, 1.0)
}
}
- };
+ }, ;
/**
* Obtain the stochastic parameters for the cold start models.