Background:
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
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).
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.
Since i can't profile into the hosting, i created a page to retrive some memmory information, this is the result:
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:
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".
- 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:
How to disable Server GC in ASP.NET Framework App running on Azure App Service