3

Background:

  1. I have 2 web applications hosted in Hostgator. One of them is MVC 5/ EF 6 / .Net 4.6.1, and the other one is Web Api2 / EF 6 / .Net 4.6.1

  2. Hostgator limits teh private memory of each app pool to 250MB, if the limit is reached the app pool is recycled, if the recycle happens 5 times in 5 minutes then the app pool is stopped (Rapid-Failure Potection).

  3. After several days of research i can say that all the DBContext are getting disposed. The managed memory is abou 20MB, and the unmanaged memory is about 200MB.

  4. Since i can't profile into the hosting, i created a page to retrive some memmory information, this is the result:

Hosting Values

this is the code in the controller (two lines commented because lack of permissions on the hosting server):

    model.ProcessMem = proc.PrivateMemorySize64;
    model.GCMemory = GC.GetTotalMemory(true);
    model.IsGCServer = GCSettings.IsServerGC;
    //model.CPUCounter = cpuCounter.NextValue();
    //model.RAMCounter = ramCounter.NextValue();
    

I used Ant profiler to get information on my local machine, this is the result:

profiler snapshot

profiler timeline

As you can see most of the memory is allocated in advance by .Net (I understant this is more efficient than allocating several small parts), but this unused memory is counting as part of the "app pool process memmory". I now the GC can collect them if needed, but as the server has several GB of memory left, and the GC is not aware of the memory limit in the app pool configuration, then it is ignoring it because "is not need yet".

  1. My research takes me to the Garbage Collector Mode (Server/Workstation), so it looks like the solution, but when I change the value into the web.config it does not take effect. Tested on VS2017, on local IIS and on the Hosting.

Question:

Is it posible to change the setting to use Workstation GC? Or Is there any way to limit the Private Memory allocated by .Net in advance? Or any way to keep it low?

Related Post:

https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/gcserver-element

How to disable Server GC in ASP.NET Framework App running on Azure App Service

Generation 1 Heap Consuming Gigs of Memory as Free Space

  • on asp.net core you can set in `.csproj` or after build/publish in the `.runtimeconfig.json` file `("System.GC.Server": false,)`, and it works for me memory went down from 200MB to 7MB, but now I'm looking how to do the same for MVC5 – buga Feb 17 '23 at 20:02

1 Answers1

0

If you are using their shared hosting, you can't change your Private Memory limit, you need to ask them to change it for you. Or to avoid above issue, maybe you need to upgrade to higher plan. Feel free to contact their support first about the issue that you encounter

TheGunners
  • 127
  • 2