2

What's going on behind the scenes when an AWS lambda function freezes?

That is -- many of the Lambda Runtime Docs refer broadly to the concept of a function freezing or unfreezing

The runtime and each extension indicate completion by sending a Next API request. Lambda freezes the execution environment when the runtime and each extension have completed and there are no pending events.

My understanding of this is that after a Lambda function initializes (or "cold starts") and executes the first invocation request, if there are no other invocations to process the function's execution environment will "freeze". Then, when there's another function invocation to process, the function's execution environment will "unfreeze" almost instantly without needing to initialize/cold-start again. If a frozen function goes too long without being invoked it will shutdown, and the next invocation request will need to cold start.

Does anyone know what this freezing is? It's my understanding that these execution environments are firecracker virtual machines. Is this freezing something that firecracker supports, or is it some extra magic that AWS Web Services has that they keep to themselves? Put another way, if I have a Firecracker VM running can I freeze and unfreeze it?

Alana Storm
  • 164,128
  • 91
  • 395
  • 599
  • 1
    I don't think AWS has shared anything here. But per this [blog post](https://aws.amazon.com/blogs/aws/firecracker-lightweight-virtualization-for-serverless-computing/), the Firecracker process is jailed using [cgroups](https://en.wikipedia.org/wiki/Cgroups), so perhaps [cgroup freezer](https://www.kernel.org/doc/Documentation/cgroup-v1/freezer-subsystem.txt)? – jarmod Mar 03 '22 at 23:48

1 Answers1

3

We can understand the freeze as after each execution, AWS Lambda putting the instance to sleep. In other words, the instance freezes (similar to a laptop in hibernate mode). The virtual CPU is turned off. This frees up resources on the worker node. The overhead from waking up such a function is negligible.

For understand how Firecracker works under the hood, take a look on this AWS re:Invent of 2019 video: AWS re:Invent 2019: Firecracker open-source innovation (OPN402)

Also, take a look on this posts:

valdeci
  • 13,962
  • 6
  • 55
  • 80
  • 1
    Thank you @valdeci, that's useful information. One clarifying question -- when you say "We can understand the freeze as after each execution, AWS Lambda putting the instance to sleep." -- are you saying that the freeze is _literally_ just the firecracker VM being put to sleep and its wakeup is fast because firecracker VMs are fast, or are you saying we can effectively think of it the same way as sleeping but that the mechanism for achieving this is something different that we shouldn't worry about? – Alana Storm Mar 05 '22 at 18:03