Cold Start
As we know, Azure totally manages Azure functions.
Means that after some time of inactivity, Azure might shut down the functions host since if it will notice that the compute power is not used, then it will bring it down.
That implies the next function activation will take time since the underlying infrastructure, the underlying host, has to be powered up.
That implies a delay you should know about since this activation could last two or three seconds before the code runs.
What type of trigger it occurs?
Especially in the async triggers like queues, timers, and so on, this is not an issue in most kinds of functions. But with HTTP-triggered functions, this is going to be an issue as HTTP requests are synchronous and the calling party expects a rapid response. If the function is only starting up, this will take time. So this is essentially what occurs with cold start.
Steps in Code start
At the time of cold run. when the app is called, meaning the host is powered on,
- Azure first allocates un-specialised server;
- then the worker becomes specialized when the function should be triggered. It means it gets ready for the function activation,
- file mounted to workers
- App settings applied
- then the function runtime resets or reloads.
- functions json read
- Extensions loaded
- The functions themselves are loaded into memory;
only then does the code run.
Therefore, all those four actions preceding the actual code activation could take time. Once more, often between two and three seconds.
Steps in App already in Warm start
The only thing Azure has to do is really run the code when the app is warm and the function should be triggered. The reaction time naturally will be significantly improved.
How to avoid cold start?
- By selecting the right hosting plan.