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 plan
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.

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

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.