简体   繁体   English

垃圾收集 - 改变收集器算法

[英]Garbage Collection - Changing Collector Algorithm

We are running our Spring+Hibernate web app on Tomcat (Java 1.5). 我们在Tomcat(Java 1.5)上运行Spring + Hibernate Web应用程序。 Currently we use 2GB of heap space (I am told it is the max possible on Solaris 32 bit servers although Server has a total of 16GB RAM). 目前我们使用2GB的堆空间(我被告知它是Solaris 32位服务器上的最大可能,尽管Server总共有16GB RAM)。 The current JAVA_OPTS are : 目前的JAVA_OPTS是:

-XX:MaxPermSize=512m -XX:+UseParallelGC -Xms2048m -Xmx2048m -XX:MaxPermSize = 512m -XX:+ UseParallelGC -Xms2048m -Xmx2048m

The Young Gen + Survivor space is ~600 MB and Old Gen is 1.4 GB. Young Gen + Survivor空间约为600 MB,Old Gen为1.4 GB。

There are time when the memory gets full and we need to restart Tomcat. 有时间内存已满,我们需要重启Tomcat。 The following are the observations: 以下是观察结果:

  1. In approx 16 hour active running of the server, the GC spends around an hour for MarkSweep (~300 collections - Old Gen) and 5 - 7 minutes on Scavenging (~1500 collections - Young Gen). 在大约16小时的服务器主动运行中,GC花费大约一个小时用于MarkSweep(约300个收集 - Old Gen)和5-7分钟用于清除(~1500个收集 - Young Gen)。
  2. There are times when the Old Gen get full in 10 minutes and we need to restart the server. 有些时候Old Gen会在10分钟内完成,我们需要重新启动服务器。 Identifying the thread that is causing is has not been very successful 识别导致的线程并不是很成功

We would like to change to the following JAVA_OPTIONS - I need feedback on whether this is sensible choice (UAT environments do not match the load of Prod env and we are unable to replicate the same in UAT) 我们想更改为以下JAVA_OPTIONS - 我需要反馈是否这是明智的选择(UAT环境与Prod env的负载不匹配,我们无法在UAT中复制相同的内容)

  1. Add -Xmn1024m - This is to make sure that the Young Gen objects don't easily get promoted to Old Gen. Any suggestions on increasing / decreasing this ? 添加-Xmn1024m - 这是为了确保Young Gen对象不容易升级为Old Gen.有关增加/减少这个的任何建议吗? Also this would lead to more Young Gen GC and lesser Old Gen GC. 这也将导致更多的Young Gen GC和较小的Old Gen GC。

  2. -XX:+UseParallelOldGC - This is to make the Young and Old Gen GC run multiple threads so that they gets GCed quicker. -XX:+ UseParallelOldGC - 这是为了让Young和Old Gen GC运行多个线程,以便更快地获得GC。

  3. Is the limitation of 2GB applicable to Solaris Servers too ? 2GB的限制是否也适用于Solaris服务器? Cant the heap be increased to more than 2GB ? 堆不能增加到超过2GB?

Please share your thoughts on the above. 请分享您对上述内容的看法。

Thanks, Midhun 谢谢,Midhun

If you experienced too long major collections pause you should consider use -XX:+UseConcMarkSweepGC (and also keeping the -XX:+UseParallelOldGC ) in order to perform GC concurrently. 如果您经历了太长时间的主要集合暂停,则应考虑使用-XX:+UseConcMarkSweepGC (并保留-XX:+UseParallelOldGC )以便同时执行G​​C。

The fact you use -Xms2048m -Xmx2048m can be a bad idea, if those values are not quite good you don't let the JVM scales them (but if your sure no problem). 您使用-Xms2048m -Xmx2048m的事实可能是一个坏主意,如果这些值不是很好,您不要让JVM扩展它们(但如果您确定没问题)。 In Java Performance Tuning 2nd Ed. Java性能调优第二版中。 5 frequent suggestion are made about heap size : 关于堆大小的5个常见建议:

  1. Set the starting heapsize the same as the max heap size 将起始堆大小设置为与最大堆大小相同
  2. Set the starting size to the size needed by the max number of alive objects and set the max to 4 times this amount 将起始大小设置为最大活动对象数所需的大小,并将最大值设置为此数量的4倍
  3. Set the starting heap to max heap size 将起始堆设置为最大堆大小
  4. Set the starting heap size between 1/10 and 1/4 the max heap size 将起始堆大小设置为最大堆大小的1/10到1/4
  5. Use the default initial heap size 使用默认的初始堆大小

(Try to find the best for you) (尽量找到最适合你的)

This doc give good advice to resolve GC issue , read carrefully paragraphe about Generation Size Adjustments and try some of the command to print your GC activity, some of them can really be helpful to see some bottlenecks in your app or in your GC config. 本文提供了解决GC问题的良好建议,仔细阅读有关生成大小调整的一些命令,并尝试使用某些命令打印您的GC活动,其中一些可以帮助您查看应用程序或GC配置中的一些瓶颈。

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

相关问题 需要帮助以了解可用的JVM“垃圾收集算法”和“垃圾收集器” - need help to understand available JVM “Garbage Collection Algorithm” and “Garbage Collector” 更改对象和垃圾收集器的引用 - Changing reference of object and garbage collector 如何在Tomcat中设置自定义垃圾收集器算法 - How to Set a Custom Garbage Collector Algorithm in Tomcat 使用并发标记扫描收集器进行主要垃圾收集? - Major Garbage collection with Concurrent Mark Sweep Collector? 如何避免垃圾收集器收集对象 - How to avoid object collection by garbage collector 如何通过GC(垃圾收集器)标记一个对象进行垃圾收集? - How to mark an object for garbage collection by the GC (Garbage Collector)? 在垃圾收集语言中实现垃圾收集器是否有意义 - Does it make sense to implement a Garbage Collector in a Language with Garbage Collection Java垃圾收集:什么是并行收集器中的虚拟空间? - Java garbage collection : what is virtual space in parallel collector? Java垃圾收集背后的理论和算法 - Theory and algorithm behind Java garbage collection 为什么其他语言没有像Java Garbage Collector那样具有自动垃圾收集功能? - Why other languages don't have automatic garbage collection similar as that of the Java Garbage Collector?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM