简体   繁体   English

为什么在小堆上使用完整的gc需要5秒钟?

[英]Why will a full gc on small heap takes 5 seconds?

I am running an J2EE application on 3 year old Solaris system with a used heap that is about 300 MB. 我在3岁的Solaris系统上运行J2EE应用程序,使用的堆约为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. 从gc日志中,我看到每天触发几次的完整gc大约需要5秒钟,并且每次恢复大约200 MB。 What could be the reason for a full gc to take such a long time on such a small heap? 一个完整的gc在这么小的堆上花费这么长时间的原因可能是什么?

I run java 1.6.0_37. 我运行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 (ie GC ergonomics), and at last the number of object residing in the heap. 缓慢的完整GC(以及次要的GC)主要是由于硬件设置不佳,其次是软件配置(即,GC人体工程学),最后是堆中存在的对象数量所致。

Looking at the hardware, what CPU model and vendor are you using on your Solaris? 查看硬件,您在Solaris上使用什么CPU型号和供应商? Is it a SMP system with more than one core. 它是具有多个核心的SMP系统吗? Do you have more than one thread per core? 每个核心是否有多个线程? Do your GC utilize all available virtual processors on the system ie is the garbage collection distributed across more than one processor? 您的GC是否利用系统上所有可用的虚拟处理器,即垃圾回收是否分布在多个处理器上?

Another situation making full GC to perform slow is if a part of the heap is swapped out from main memory. 使完整GC变慢的另一种情况是堆的一部分从主内存中换出了。 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, ie CPU and memory? 系统上的其他任何应用程序是否会争夺相同的物理资源,即CPU和内存?

Looking at the GC ergonomics, what collector are you using? 查看GC的人体工程学,您正在使用什么收集器? I would recommend the parallel throughput collector or the G1 collector using multiple collector threads. 我建议使用多个收集器线程的并行吞吐量收集器或G1收集器。 I would also recommend to use a NUMA configuration. 我也建议使用NUMA配置。

Some general rules: 一些一般规则:

  • The better hardware and GC ergonomics, the faster the individual garbage collections will perform. 硬件和GC的人机工程学越好,各个垃圾收集的执行速度就越快。
  • 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人体工学的更多信息, 请访问http : //www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM