是否有可能燮preSS的Gen 2 GC收集.NET? [英] Is it possible to suppress gen 2 GC collection in .NET?

查看:215
本文介绍了是否有可能燮preSS的Gen 2 GC收集.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序分配一个非常大的数字,包括长寿命DAWG实例。在此DAWG的建设,有次当进度变慢100倍,而这种相关性完美地与.NET进行第2代GC集合。在此期间,将在%GC时间为99.5%,而总根2集合递增每隔几秒钟。之后的若干背到背根2集合的,他们停止触发没有明显的理由,程序加快了。几分钟后,循环重新开始。

My program allocates a very large number of instances that comprise a long-lived DAWG. During the construction of this DAWG, there are times when the progress slows down 100 fold, and this correlates perfectly with .NET performing gen 2 GC collections. During these periods, the "% time in GC" is 99.5%, and the "total gen 2 collections" increments every few seconds. After several back-to-back gen 2 collections, they stop triggering for no obvious reason and the program speeds up again. A few minutes later, the cycle restarts.

我创建实例的数量是2500万的量级,而他们采取的RAM高达几个GB,所以这不是太奇怪了第2代收集利用这个长。令人惊讶的是,第二代的集合进来火车,并得到不断触发。

The number of instances I create is on the order of 25 million, and they take up several GB of RAM, so it's not too surprising that the gen 2 collections take this long. What is surprising is that gen 2 collections come in "trains", and get triggered continually.

我可以以某种方式prevent这不完全重新考虑我的方法呢?也许有一些办法要求.NET暂停Gen 2的集合,直至另行通知?该程序运行非常有效,除了这些事件,所以.NET明显挺了起来把这个任务除了这个不幸的极端情况的行为。

Can I somehow prevent this without completely rethinking my approach? Perhaps there's some way to ask .NET to suspend gen 2 collections until further notice? The program runs very efficiently apart from these occurrences, so .NET is clearly quite up to this task apart from this unfortunate corner-case behaviour.

(我试着设置GCSettings.LatencyMode到GCLatencyMode.Batch,但问题仍然。可用物理内存量在当时的选区开始发生大约为1GB,这是一个64位的机器上。)

(I tried setting GCSettings.LatencyMode to GCLatencyMode.Batch, but the issue remained. The amount of free physical RAM at the time the GCs start happening is around 1GB. This is on a 64-bit machine.)

推荐答案

在.NET 4.5 +,你可以通过使用新的 GCLatencyMode 选项。

In .NET 4.5+ you can specify your preference for fewer Gen 2 collections by using the new GCLatencyMode options.

GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency;

在这里更多信息:

More info here:

<一个href="http://blogs.msdn.com/b/dotnet/archive/2012/07/20/the-net-framework-4-5-includes-new-garbage-collector-enhancements-for-client-and-server-apps.aspx" rel="nofollow">http://blogs.msdn.com/b/dotnet/archive/2012/07/20/the-net-framework-4-5-includes-new-garbage-collector-enhancements-for-client-and-server-apps.aspx

我的应用程序,在一定的时间窗口不能忍受暂停

.NET开发越来越一部分已建成的商业应用程序和   ,根据定义的业务交付成果服务   需求或服务水平协议。股票市场服务的例子是必须   提供非常及时的结果,而市场是开放的。通常,这些   应用程序在时间内完成显著工作的时候,他们希望   提供低延时的效果。然而,他们无法容忍明显   暂停由于集合。

A growing subset of .NET developers has built commercial apps and services that deliver results according to defined business requirements or SLAs. Stock markets are examples of services that must deliver very timely results while markets are open. Typically, these apps perform significant work during the time when they want to deliver low-latency results. Yet they cannot tolerate noticeable pauses due to a collection.

我们的客户告诉我们,他们将上部署更多​​的内存,其   这是典型的服务器,如果这样做将消除长时间的暂停时间(   通过全面阻塞GCS)出台。在.NET Framework 4.5中,我们   通过引入SustainedLowLatency模式,条件是选项,它   避免了全阻断选区。此模式也可用于   工作站GC在.NET Framework 4,通过更新4.0.3。

Our customers have told us that they would deploy more memory on their servers if doing so would remove long pause times (which are typically introduced by full blocking GCs). In the .NET Framework 4.5, we provided that option by introducing SustainedLowLatency mode, which avoids full blocking GCs. This mode is also available for the workstation GC in the .NET Framework 4 via Update 4.0.3.

虽然SustainedLowLatency设置生效,0代,   第1代和背景第2代收集仍时有发生,并   通常不引起明显的暂停时间。一种阻塞第2代   收集发生仅当机器是低存储器,或者如果该应用   通过调用GC.Collect的诱导GC()。重要的是,部署非常关键   使用该SustainedLowLatency设置到具有机应用程序   足够的内存,所以他们会满足堆所产生的增长   而设置生效。

While the SustainedLowLatency setting is in effect, generation 0, generation 1, and background generation 2 collections still occur and do not typically cause noticeable pause times. A blocking generation 2 collection happens only if the machine is low in memory or if the app induces a GC by calling GC.Collect(). It is critical that you deploy apps that use the SustainedLowLatency setting onto machines that have adequate memory, so they will satisfy the resulting growth in the heap while the setting is in effect.

在.NET Framework 4.5,SustainedLowLatency模式可用于   工作站和服务器GC。要打开它,设置   GCSettings.LatencyMode属性GCLatencyMode.SustainedLowLatency。   .NET框架4包括LowLatency模式工作站GC;   但是,此设置只打算用于短期   时间,而SustainedLowLatency模式旨在用于多   更长的时间。

In the .NET Framework 4.5, SustainedLowLatency mode is available for both workstation and server GC. To turn it on, set the GCSettings.LatencyMode property to GCLatencyMode.SustainedLowLatency. The .NET Framework 4 includes a LowLatency mode for workstation GC; however, this setting is only intended to be used for short periods of time, whereas SustainedLowLatency mode is intended to be used for much longer.

还有 NoGCRegion ,你可以试试。

https://msdn.microsoft.com/en-us/library/system.runtime.gclatencymode%28v=vs.110%29.aspx

表示垃圾收集被暂停,而应用程序是   执行的关键路径。 NoGCRegion是一个只读值;那是,   你可以不NoGCRegion值分配给GCSettings.LatencyMode   属性。通过调用指定没有GC区延时模式   TryStartNoGCRegion方法,并通过调用终止   EndNoGCRegion方法。

Indicates that garbage collection is suspended while the app is executing a critical path. NoGCRegion is a read-only value; that is, you cannot assign the NoGCRegion value to the GCSettings.LatencyMode property. You specify the no GC region latency mode by calling the TryStartNoGCRegion method and terminate it by calling the EndNoGCRegion method.

这篇关于是否有可能燮preSS的Gen 2 GC收集.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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