Azure function in app service plan triggered by service bus queue is sometimes not waking up

Dy Zapra, Keisha Marie 25 Reputation points
2023-06-26T06:52:38.25+00:00

We have a function app triggered by a service bus queue. The function app uses a basic app service plan and has Always on turned off.

Some time after the function runs, the job host stops and this is when the issue starts.

When a new message is queued into the service bus queue, the function sometimes wakes up and processes it properly but sometimes it does not, even after days, as if the cold start is not even being initiated.

Why is this happening? What's the underlying mechanism here? Shouldn't it always at least cold start?

We noticed the pattern where the cold start is not being initiated when the function was triggered shortly after it was cleaned up due to inactivity.

No startup error seen in the logs too by the way.

We saw the function wake up to process messages a day after the messages arrived in the service bus- was that the "cold start"?

The Azure documentation (https://learn.microsoft.com/en-us/azure/azure-functions/dedicated-plan) did say that we should enable always on for the function app "to work properly" but never expounded on why and what would happen. I read somewhere that always on does not affect the billing- why is always on allowed to be toggled off? is there a specific scenario where that is needed?

Screenshot 2023-06-26 at 09.34.36

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,341 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,203 questions
{count} vote

1 answer

Sort by: Most helpful
  1. SnehaAgrawal-MSFT 22,166 Reputation points
    2023-07-06T17:00:40.6166667+00:00

    @Dy Zapra, Keisha Marie Apologies for late response here!

    It is possible that the cold start is not being initiated due to the way that the Azure Functions runtime works.

    When a function app is hosted on a basic app service plan, the underlying infrastructure is shared with other apps. This means that the app may be unloaded from memory when it is not being used to free up resources for other apps.

    When a new message is queued into the service bus queue, the function app needs to be loaded into memory again, which can cause a delay in processing the message.

    The Always On feature in Azure App Service keeps the app loaded in memory all the time, which can help reduce the delay in processing messages. However, this feature is not available on basic app service plans.

    To address this issue, you can try the following steps:

    Upgrade your app service plan to a higher tier that supports Always On. This will keep your app loaded in memory all the time, which can help reduce the delay in processing messages.

    Use the Premium plan for your function app. The Premium plan provides dedicated resources for your app, which can help improve the performance and reduce the delay in processing messages.

    Use the Consumption plan for your function app. The Consumption plan automatically scales your app based on the number of incoming messages, which can help reduce the delay in processing messages.

    Optimize your function code to reduce the cold start time. You can do this by using lightweight dependencies, reducing the size of your function code, and optimizing the initialization code.

    I hope this helps! Let me know if you have any further questions.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.