在.NET 4.0中非常高的内存使用情况 [英] Very High Memory Usage in .NET 4.0

查看:375
本文介绍了在.NET 4.0中非常高的内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#Windows服务,我最近从.NET 3.5到.NET 4.0感动。没有其他的code进行了更改。

I have a C# Windows Service that I recently moved from .NET 3.5 to .NET 4.0. No other code changes were made.

在3.5上运行时,对于一个给定的工作负载的内存utilzation是大约1.5 GB的内存和吞吐量是每秒20倍。 (在X无所谓这个问题的情况下。)

When running on 3.5, memory utilzation for a given work load was roughly 1.5 GB of memory and throughput was 20 X per second. (The X doesn't matter in the context of this question.)

在4.0上运行完全相同的服务3GB和5GB +之间所使用的内存,并得到小于每秒4×。事实上,该服务通常会最终拖延了内存使用量继续攀升,直到我的系统是选址在99%的使用率和页面文件交换去坚果。

The exact same service running on 4.0 uses between 3GB and 5GB+ of memory, and gets less than 4 X per second. In fact, the service will typically end up stalling out as memory usage continue to climb until my system is siting at 99% utilization and page file swapping goes nuts.

我不知道这是否有做垃圾回收,或者什么,但我无法计算出来。我的窗口服务使用通过配置文件切换服务器GC如下所示:

I'm not sure if this has to do with garbage collection, or what, but I'm having trouble figuring it out. My window service uses the "Server" GC via the config file switch seen below:

  <runtime>
    <gcServer enabled="true"/>
  </runtime>

更改此选项设置为false似乎并没有有所作为。 Futhermore,从阅读我在4.0上新的GC完成,大的变化只是影响了工作站GC模式,而不是服务器GC模式。因此,或许GC无关的问题。

Changing this option to false didn't seem to make a difference. Futhermore, from the reading I've done on the new GC in 4.0, the big changes only effect the workstation GC mode, not server GC mode. So perhaps GC has nothing to do with the issue.

想法?

推荐答案

嗯,这是一个有趣的。

在.NET 4.0上运行这个当的根本原因原来是SQL Server报表服务LocalReport类(V2010)的行为的改变。

The root cause turns out to be a change in the behavior of SQL Server Reporting Services' LocalReport class (v2010) when running this on top of .NET 4.0.

基本上,微软改变了RDLC处理的行为,这样一个报告,处理它是在一个单独的应用程序域这样做每次。这实际上是做了专门解决因无法卸载的应用程序域组件内存泄漏。当LocalReport类处理的RDLC文件,它实际上是建立在飞行并将其加载到应用程序域的组件。

Basically, Microsoft altered the behavior of RDLC processing so that each time a report was processed it was done so in a seperate application domain. This was actually done specifically to address a memory leak caused by the inability to unload assemblies from app domains. When the LocalReport class processed an RDLC file, it actually creates an assembly on the fly and loads it into the app domain.

在我的情况下,由于体积大报告我处理,这是造成非常大的数字System.Runtime.Remoting.ServerIdentity对象被创建。这是我通风报信的原因,因为我很困惑,为什么处理的需要RLDC远程处理。

In my case, due to the large volume of report I was processing, this was resulting in very large numbers of System.Runtime.Remoting.ServerIdentity objects being created. This was my tip off to the cause, as I was confused as to why processing an RLDC required remoting.

当然,调用一个类的方法在另一个应用程序域,远程处理是你用什么。在.NET 3.5中,这是没有必要的,默认情况下,该RDLC组件加载到相同的应用程序域。在.NET 4.0,但是,一个新的应用程序域默认情况下创建。

Of course, to call a method on a class in another app domain, remoting is exactly what you use. In .NET 3.5, this wasn't necessary as, by default, the RDLC-assembly was loaded into the same app domain. In .NET 4.0, however, a new app domain is created by default.

此修复程序是相当容易的。首先,我需要去使用下面的配置使传统的安全策略:

The fix was fairly easy. First I needed to go enable legacy security policy using the following config:

  <runtime>
    <NetFx40_LegacySecurityPolicy enabled="true"/>
  </runtime>

接下来,我需要通过调用下面强制RDLCs在同一个应用程序域作为我的服务进行处理:

Next, I needed to force the RDLCs to be processed in the same app domain as my service by calling the following:

myLocalReport.ExecuteReportInCurrentAppDomain(AppDomain.CurrentDomain.Evidence);

这解决了问题。

这篇关于在.NET 4.0中非常高的内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆