如何在Azure App Service上运行的ASP.NET Framework App中禁用服务器GC [英] How to disable Server GC in ASP.NET Framework App running on Azure App Service
问题描述
我正在Azure应用服务上进行一些ASP.NET MVC 5/WCF应用程序的高密度托管,鉴于内存转储显示了GC堆只有约40MB的可用空间.我怀疑这是由于服务器GC引起的,因此我尝试按照 https://docs.microsoft.com/zh-cn/dotnet/framework/configure-apps/file-schema/runtime/gcserver-element 并添加
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://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/gcserver-element and adding
<gcServer enabled="false" />
到我的web.config,但这似乎没有任何作用
to my web.config, but this does not appear to have any effect as
GCSettings.IsServerGC
仍返回true.我在这里想念什么?
is still returning true. What am i missing here?
使用普通的IIS,可以使用 https://weblogs.asp.net/owscott/setting-an-aspnet-config-file-per-application-pool ,但是在Azure App Service中,您没有执行此操作的权限.
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.
推荐答案
好吧,首先,看来您可能需要使用GC.Collect()手动调试组件的内存使用情况: https://docs.microsoft.com/en-us/dotnet/api/system.gc.collect?view = netcore-3.1
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
通过这种方式,您可能可以查明代码的特定部分,这些部分由于垃圾回收不好而导致内存泄漏,或者使用了某些第三方库.
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.
一旦完成了这一相当繁琐的部分,然后根据您认为导致问题的原因,应该考虑使用(使用var item = new NameOfClass())对代码块进行手动处置.
甚至尝试在导致它的类上实现 IDispose
:
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.
这篇关于如何在Azure App Service上运行的ASP.NET Framework App中禁用服务器GC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!