'Azure Function App is very slow, but only sometimes
I have read through most of the questions that seems to be similar to what I'll ask so hopefully I'm not wasting anyone's time.
We have a Function App in Azure Cloud that contains several Durable Functions. One of these durable functions is a HTTP trigger API REST call. It will normally take between 0.5 - 3 seconds to execute fully (from call to done, delivered result). But sometimes it takes 20-35 seconds. I don't know why or how I can search for errors.
The durable function fetches information from a Cosmos DB and delivers the result back to the caller.
Function App, Durable Function and Cosmos DB are all located in the same Region. (Checked that). The Durable Function is set to B2:2 and has toggled Always On to ON.
Is there something I miss or something I should check to make sure it runs smoother?
I greatly appreciate everyone's time and energy they put into helping me. Thanks a lot.
---- Additions to the post after posting ----
I have checked the interactive tool and if I read that correctly it tells me a maximum execution time of 0.8 seconds and a maximum network lag of 6 seconds. That would indicate something that I suspected before I set up this post and that is that Azure needs to cold start the function. But I have always on toggled on so why?
It doesn't seem to take 30 seconds to complete the function. It seems to take less than 1 second to complete the function and up to a maximum of 6 seconds lag, but where are the other 23 seconds going in a 30 second call?
B2:2 is the service agreement I have with Azure. B2 is the test environments second paid state with 2 instances scaling (I have changed that to 3 after posting this). Application Insights are on and no other dependencies are present except the Cosmos DB.
Solution 1:[1]
AFAIK in Azure Functions,
- After 5 minutes of inactivity, Function App goes to the cold state. To come out of it, 10 seconds delay occurs.
- Even the Function App is in Hot State, it will take some excessive amount of time to load the external libraries defined in it.
- In the Function App, Code Logic Performance also matters the cause of slowness in the Azure Functions.
There are few steps for reducing the cold-start times particularly for the Functions having external libraries:
- Running from a package file
WEBSITE_RUN_FROM_PACKAGEto1may reduce cold-start times, particularly for JavaScript functions with largenpmpackage trees. - From the Azure Portal >
Diagnose and solve problems> Troubleshoot Performance category to identify the causes of slowness:


- Try
Always OnFeature available in App Service Plan and Premium Plan of the Azure Functions to prevent such issues. - Regarding the Performance and reliability improving of Azure Functions, please refer here.
If this issue persists still, then please raise an incident with Microsoft Support to get the root cause and resolution.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HariKrishnaRajoli-MT |

