是什么触发了第二代的垃圾收集? [英] What triggers a gen2 garbage collection?

查看:109
本文介绍了是什么触发了第二代的垃圾收集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的情况,我想弄清楚。

I have an odd situation I am trying to figure out.

创世纪:

我在一台物理机器上运行我的程序是 16 内核和 128GB 的RAM。我想,以确定为什么它不使用所有可用的核心,它通常使用的平均水平(16,所以4-5个核心)20-25%的CPU。当我看性能计数器他们表现出60-70%的时间在垃圾收集的顺序。

I am running my program on a physical machine with 16 cores and 128GB of RAM. I am trying to determine why it is not using all available cores, typically it uses 20-25% CPU on average (so 4-5 cores of the 16). When I look at performance counters they show on the order of 60-70% Time in Garbage Collection.

有关的参考,我使用的.NET Framework 4和TPL(Parallel.ForEach)线程我的程序的性能密集型部分。我限制的线程数来核心的数量。

For reference, I am using .NET Framework 4 and the TPL (Parallel.ForEach) to thread the performance-intensive portion of my program. I am limiting the number of threads to the number of cores.

的问题:

我创造了大量的对象,太多的垃圾收集处理效率,并因此花费了大量的时间在垃圾收集器。

I was creating a large number of objects, far too many for the garbage collector to handle efficiently and thus it spent a large amount of time in the garbage collector.

的简单的解决方案迄今:

我介绍对象池,以减少对垃圾收集器的pressure。我公司将继续汇集对象来提升性能,已经汇集了一些对象缩小垃圾回收时间60%-70%的时间45%,我的程序运行速度提高40%。

I am introducing object pooling to reduce the pressure on the garbage collector. I will continue pooling objects to improve performance, already pooling some objects reduced garbage collection from 60-70% of time to 45% of time and my program ran 40% faster.

挥之不去的问题(一个我希望你能回答我):

我最多14GB的可用RAM运行应用时,相对于内存128GB,这是相当小的程序。闲来无事是这台机器上运行(这是一个纯粹的测试平台对我来说),并有大量的可用RAM。

My program when running uses at most 14GB of the available RAM, compared to 128GB of RAM this is quite small. Nothing else is running on this machine (it is purely a testbed for me) and there is plenty of RAM available.

  • 如果有足够的可用RAM,为什么任何的Gen2(或全部)集合发生呢?相当多的这些第二代集合(数以千计)的发生。也就是说它是如何确定的门槛,开始第二代收藏?
  • 为什么没有垃圾回收器只是延缓任何完全收集到物理内存pressure达到了较高的门槛?
  • 有没有什么办法可以配置垃圾收集器等待一个较高的门槛? (即不打扰收集可言,如果没有必要的话)

编辑:

我已经使用的选项,使用服务器垃圾收集器......什么,我需要知道的是什么引发了第二代集合,而不是服务器垃圾回收器是更好的(我已经知道了)。

I am already using the option to use the server garbage collector ... what I need to know is what is triggering a gen2 collection, not that the server garbage collector is better (I already know that).

推荐答案

据我记忆所及,客户GC是默认的。我与它的经验是,它不会让堆得到收集之前非常大。对于我的重型加工应用,我用的是服务器GC。

As I recall, the Client GC is the default. My experience with it is that it doesn't let the heap get very large before collecting. For my heavy duty processing applications, I use the "server" GC.

您启用服务器GC在你的应用程序配置文件:

You enable the server GC in your application configuration file:

<?xml version ="1.0"?>
<configuration>
  <runtime>
    <gcServer enabled="true"/>
  </runtime>
</configuration>

这使得巨大的在我的性能差异。例如,我的项目之一是在垃圾收集花费向上80%的时间。启用服务器GC下降,要一点点超过10%。内存使用率上升,因为GC让它去,但是这对于大多数我的应用程序。

That makes a huge difference in performance for me. For example, one of my programs was spending upwards of 80% of its time in garbage collection. Enabling the server GC dropped that to just a little over 10%. Memory usage went up because the GC let it go, but that's fine for most of my applications.

另一件事,就会造成二代收藏是大对象堆。请参见 CLR内向外:大对象堆揭秘。概括地说,如果你超过蕙阈值时,就会引发Gen 2的集合。如果你分配了很多短命的大对象(约85千字节),这将是一个问题。

Another thing that will cause a Gen 2 collection is the Large Object Heap. See CLR Inside Out: Large Object Heap Uncovered. In a nutshell, if you exceed the LOH threshold, it will trigger a Gen 2 collection. If you're allocating a lot of short-lived large objects (about 85 kilobytes), this will be a problem.

这篇关于是什么触发了第二代的垃圾收集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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