Azure Function doesn't complete due to "Stopping JobHost"

Tran, Nguyen 20 Reputation points
2024-07-17T20:53:02.85+00:00

Is your question related to a specific version? If so, please specify:

function runtime v4.x

What language does your question apply to? (e.g. C#, JavaScript, Java, All)

we currently use C# .NET in-process model for our function apps (function runtime v4.x)

Function App plan:

Premium with EP1 planscale-out

Function run's info:

Executing 'LoadPeopleEmployeeAllAA' (Reason='This function was programmatically called via the host APIs.', Id=35d63f81-5b0f-472e-8743-2bdb917dbad5)

Question

We have a timer triggered function "LoadPeopleEmployeeAllAA" that transforms and loads user data from on-prem AD to SQL database (~330k users) and triggers 3 stored procedures.

While the function is triggered and executing, mid run we receive "Possible thread pool starvation detected" and "Stopping JobHost" log messages and the Job Host stops and restarts, thus causing our function run to never complete.

image

The function run's logs stops at "Fetching page 523, attempt 1", after JobHost is complete stopped.

image

It looks like the possible reason could be that the environment is running out of resources, such as memory or CPU, and is shutting down functions to free up resources (thus the triggered function never gets to complete)

So we decided to up the plan from EP1 to EP2 and the function is then able to run/complete without problems and without those log issues (ie. "Possible thread pool starvation detected" and "Stopping JobHost").

However, we want to save on costs and continue using EP1. So could I ask for any suggestions on how to do so? I'm thinking on how to optimize the code to efficiently use resources specified by EP1 plan; Is this the right approach? I can share more details about the function code if needed.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,830 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 27,451 Reputation points Microsoft Employee
    2024-07-23T02:52:38.1866667+00:00

    Hi @Tran, Nguyen,

    I suggest referencing Monitoring data reference for Azure Functions | Microsoft Learn to get started on what metrics are available that you can begin to analyze. I also strongly suggest using the Diagnose and solve problems blade on your function app to use the various tools that will assist you with capture telemetry and behavior of your app. That should help you determine when and where the resource constraints are occurring.

    0 comments No comments

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.