How to change GC Mode on Azure Function App hosted In-Process

Krzysztof Madej 26 Reputation points

I want to test my Function app written in C# (dotnet 6) with different GC mode. The app is hosted on dedicated Linux plan with server GC mode. I set DOTNET_gcServer to 0 but System.Runtime.GCSettings.IsServerGC is strill true, and memory consumtpion remain the same. How can I change GC mode for app hosted In-Process?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,607 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,603 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce ( 60,866 Reputation points

    the GC mode is not settable with azure functions. also as they are always a single cpu with 1.5 gb max memory, its aways the same as workstation mode.

    0 comments No comments

  2. MughundhanRaveendran-MSFT 12,446 Reputation points

    Hi @Krzysztof Madej ,

    Thanks for reaching out to Q&A forum.

    By default, the GC mode in Azure functions is server GC. We have kept it as server GC for best performance and memory management. The major difference between these 2 GC flavors is WKS GC has one heap and SVR GC has as many heaps as there are logical cores on the machine, with the same # of GC threads doing GC work. Due to the different nature of the 2 kinds of workloads, SVR GC has 2 distinctly different attributes that WKS GC does not have -

    • SVR GC threads' priority is set to THREAD_PRIORITY_HIGHEST which means it would preempt other threads if they were lower priority, which most theads are. In comparison, WKS GC runs the GC work on the user thread that triggered the GC so it's whatever priority that thread runs at which is usually normal priority.
    • SVR GC threads are hard affinitized to logical cores.

    So for an Azure functions running on a consumption plan, the GC really doesnt make a difference as it would only run on a single core with 1.5 GB RAM. However if you choose a higher SKU such as premium or dedicated P3V3 plan with more number of cores, it would be ideal to keep the GC mode as SVR GC.

    Learn more about Server GC :

    I hope this helps and you would choose to have SVR GC in Azure functions. Please let me know if you would still like to change to WKS GC.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.