10

I'm doing some high density hosting of ASP.NET MVC 5 / WCF apps on Azure App Service and the idle apps are using 600~1000MB of memory each which is quite a lot, given that a memory dump reveals that the GC heap is only about ~40MB full. I suspect this is due to server GC so i tried disabling it by following https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/gcserver-element and adding

<gcServer enabled="false" />

to my web.config, but this does not appear to have any effect as

GCSettings.IsServerGC

is still returning true. What am i missing here?

EDIT:

Using normal IIS it can be done using https://weblogs.asp.net/owscott/setting-an-aspnet-config-file-per-application-pool but in Azure App Service, you lack the permissions to do this.

Suchiman
  • 1,636
  • 2
  • 20
  • 30
  • 1
    What is the problem you think you have? Apps using too much memory? Sounds to me like you think you have a problem but you don't. – Neil Feb 28 '20 at 11:17
  • 1
    @Neil as i've explained, the apps are using up to a 1GB of memory, doing nothing and as i've analyzed, the GC heap has only about 40MB of utilization. Server GC is known to have a higher memory footprint than workstation GC so having more efficient memory utilization is more important than the benefits of server gc for me in this case. – Suchiman Feb 28 '20 at 11:31
  • If they do not really use it then while they claim it, it is not really there. Which means you hunt ghosts (reservation not usage). – TomTom Mar 01 '20 at 16:33
  • 1
    @TomTom i mean, it still takes up physical resources in my App Service Plan which is at like 80% memory utilization. It's just not used effectively. – Suchiman Mar 01 '20 at 16:54
  • Did you set your `web.config` property `copy to Output directory` as `copy always` when publish app to azure? If not, it will not work with gcServer . – Joey Cai Mar 02 '20 at 03:09
  • The question is *How to enable/disable Server GC in Azure?* but you're trying to solve a potential memory leak. I thighly recommend you go through this very similar QA: https://stackoverflow.com/questions/25993290/mvc-asp-net-is-using-a-lot-of-memory – Jeremy Thompson Mar 02 '20 at 04:29
  • @JoeyCai yes, i've verified that the config is deployed correctly by going to the app service editor and inspect the `web.config` there. – Suchiman Mar 02 '20 at 10:45
  • @JeremyThompson yes the behavior is quite similiar to that question, that's why i want to switch to workstation GC which acts way more aggressive in keeping the heap size down, contrary to server GC which permits quite large heaps to reduce collection frequency. – Suchiman Mar 02 '20 at 10:46
  • 2
    it seems this setting doesn't work anymore for ASP.NET. I've tried and it doesn't even work in my local environment. It works fine for ASP.NET Core though. – Tom Luo Mar 04 '20 at 08:47

1 Answers1

1

Ok, first of all, it seems like you might have to manually debug the memory usage of components using GC.Collect(): https://learn.microsoft.com/en-us/dotnet/api/system.gc.collect?view=netcore-3.1

This way you might be able to pinpoint a specific part of the code that either causes a memory leak due to bad garbage collection, or parts that are using certain third-party libraries.

Once you are done with this quite tedious part, then depending on what you think is causing the problem, you should consider either using a manual disposal of the code block utilizing (using var item = new NameOfClass()) or even trying ti implement IDispose on the classes that are causing it: https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose.

Stephanos B.
  • 340
  • 3
  • 15