Cloud and Container Basics
With serverless functions (FaaS), only the first call to a function that has not been called for a while sometimes responds hundreds of milliseconds to several seconds slower. Which of the following correctly explains this phenomenon?
- AThe result of the first call is cached, and from the second call on the function code is not executed and only the stored result is returned
- BIt takes time to prepare a new environment to run the function, start the language runtime and run initialization (a cold start)
- COn the first call the function code is sent to the user's device, compiled there and then executed
Show answer and explanation
Answer: B. It takes time to prepare a new environment to run the function, start the language runtime and run initialization (a cold start)
For serverless functions, the provider prepares execution environments (such as containers or lightweight virtual machines) as needed and cleans them up when they are not used for a while. The first call after an environment has been cleaned up requires preparing the environment, starting the language runtime and running the function's initialization, and the response is slower by that amount. Subsequent calls reuse the prepared environment and are faster (a warm start). Countermeasures include keeping initialization and the libraries loaded light and using settings that keep a certain number of environments ready in advance.
- A. Function results are not cached automatically; the code runs on every call.
- B. Correct. The time to prepare and initialize the environment is added to the first call.
- C. Functions run in execution environments on the cloud side. They are not sent to the user's device to run.