为什么一个完整的gc在小堆上需要5秒? [英] Why will a full gc on small heap takes 5 seconds?

查看:120
本文介绍了为什么一个完整的gc在小堆上需要5秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在3年前的Solaris系统上运行一个J2EE应用程序,使用的堆大约为300 MB。从gc日志中我看到,每天触发几次的完整gc需要大约5秒钟,每次恢复大约200 MB。完全gc在如此小的堆上花费这么长时间的原因是什么?



我运行java 1.6.0_37。

$ b $一个缓慢的完整GC(和小事件GC)主要是由于硬件设置不良,其次是软件配置(即GC人体工程学),以及最后是堆中对象的数量。

观察硬件,您在Solaris上使用的是哪种CPU型号和供应商?它是一个拥有多个核心的SMP系统吗?你有多个核心线程吗? GC是否利用了系统中所有可用的虚拟处理器,即分布在多个处理器上的垃圾收集?

完全GC执行缓慢的另一种情况是,如果堆的一部分从主内存中被换出。在这种情况下,换出的内存页面必须在垃圾回收期间交换,这可能是一个相当耗时的过程。在这种情况下,机器上没有安装足够的物理内存。

系统上的其他应用程序是否竞争相同的物理资源,即CPU和内存?在GC人体工程学方面,您使用的是哪种收集器?我会推荐使用多个收集器线程的并行吞吐量收集器或G1收集器。我还建议使用NUMA配置。



一些常规规则:


  • 更好的硬件和GC人体工程学,单个垃圾收集将执行得越快。

  • 应用程序创建的对象越少,垃圾收集器运行的次数越少。

  • 创建的对象越少,完整的垃圾收集器运行的次数就越少。


更多信息关于GC人体工程学:
http:// www .oracle.com / technetwork / java / javase / gc-tuning-6-140523.html


I am running an J2EE application on 3 year old Solaris system with a used heap that is about 300 MB. From the gc logs I have seen that the full gc that is triggered a few times a day takes about 5 seconds and recovers about 200 MB every time. What could be the reason for a full gc to take such a long time on such a small heap?

I run java 1.6.0_37.

解决方案

A slow full GC (and minor GC for that matter) is primary a result of a poor hardware setup and secondly software configuration (i.e. GC ergonomics), and at last the number of object residing in the heap.

Looking at the hardware, what CPU model and vendor are you using on your Solaris? Is it a SMP system with more than one core. Do you have more than one thread per core? Do your GC utilize all available virtual processors on the system i.e. is the garbage collection distributed across more than one processor?

Another situation making full GC to perform slow is if a part of the heap is swapped out from main memory. In that case the memory pages swapped out must be swapped in during the garbage collection which can be a rather time consuming process. In that case you do not have sufficient physical memory installed on the machine.

Does any other applications on the system compete for the same physical resources, i.e. CPU and memory?

Looking at the GC ergonomics, what collector are you using? I would recommend the parallel throughput collector or the G1 collector using multiple collector threads. I would also recommend to use a NUMA configuration.

Some general rules:

  • The better hardware and GC ergonomics, the faster the individual garbage collections will perform.
  • The fewer and smaller objects the application creates, the less often will the garbage collector run.
  • The fewer long lived object created, the less often will the full garbage collector run.

For more information about GC ergonomics: http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html

这篇关于为什么一个完整的gc在小堆上需要5秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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