[英]How to disable Server GC in ASP.NET Framework App running on Azure App Service
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.我正在 Azure 应用服务上对 ASP.NET MVC 5/WCF 应用程序进行一些高密度托管,而空闲应用程序每个使用 600~1000MB 的内存,这相当多,因为内存转储显示 GC 堆是只有大约 40MB 满。 I suspect this is due to server GC so i tried disabling it by following https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/gcserver-element and adding我怀疑这是由于服务器 GC,所以我尝试通过遵循https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/gcserver-element并添加来禁用它
<gcServer enabled="false" />
to my web.config, but this does not appear to have any effect as到我的 web.config,但这似乎没有任何影响
GCSettings.IsServerGC
is still returning true.仍然返回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.使用普通的 IIS 可以使用https://weblogs.asp.net/owscott/setting-an-aspnet-config-file-per-application-pool来完成,但在 Azure 应用服务中,你缺乏执行此操作的权限。
Ok, first of all, it seems like you might have to manually debug the memory usage of components using GC.Collect(): https://docs.microsoft.com/en-us/dotnet/api/system.gc.collect?view=netcore-3.1好的,首先,您似乎必须使用 GC.Collect() 手动调试组件的内存使用情况: https ://docs.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://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose .一旦你完成了这个相当乏味的部分,然后根据你认为导致问题的原因,你应该考虑使用手动处理代码块(using var item = new NameOfClass())
或者甚至尝试实现IDispose
关于导致它的类: https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.