在Java中调整垃圾收集参数 [英] Tuning Garbage Collection parameters in Java

查看:88
本文介绍了在Java中调整垃圾收集参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务器java组件,它在启动时具有巨大的内存需求,逐渐减少。因此,在启动时,内存要求可能会达到4g;在最初的激增结束后将下降到2g。我已经配置了组件,以5g的内存开始,组件启动良好;使用的内存高达4克,然后下降到接近2克。在这一点上堆消耗的内存仍然徘徊在4g左右,我想把它降低(基本上保持空闲内存下降到几百MB而不是2g,我试着使用MinFreeHeapRatio和MaxFreeHeapRatio从默认值降低它们但是这会导致垃圾收集在最初的秒杀初始运行之后不会被触发,并且所使用的内存保持在比平常更高的水平。任何指针都会大大地帮助您。


如果您确实有充分的理由想想它,这可能与您正在使用的垃圾收集算法有关。一些算法会释放未使用的内存到操作系统,有些不会,有一些图表和相关的这个 http://www.stefankrause.net/wp/?p=14 。您可能想尝试G1收藏夹,因为它似乎很容易将内存释放回OS。

如果他们都选择一次最大化他们的负担呢?你确定它们中的一些将内存分页到磁盘并放慢服务器爬行?我将在具有足够内存的服务器上运行它们,以在最大堆上运行所有应用程序,为操作系统/高速缓存另外运行4-6GB。 32或64 GB的服务器很常见,你可以获得更多。


I have a server java component which has a huge memory demand at startup which mellows down gradually. So as an example at startup the memory requirement might shoot unto 4g; which after the initial surge is over will go down to 2g. I have configured the component to start with memory of 5g and the component starts well; the used memory surges upto 4g and then comes down close to 2g. The memory consumed by the heap at this point still hovers around 4g and I want to bring this down (essentially keep the free memory down to few hundred mb's rather than 2g. I tried using the MinFreeHeapRatio and MaxFreeHeapRatio by lowering them down from the default values but this resulted in garbage collection not being triggered after the initial run during the initial spike and the used memory stayed at a higher than usual level. Any pointers would greatly help.

解决方案

First, I ask why you are worried about freeing up 2 GB of ram on a server? 2GB of ram is about $100 or less. If this is on a desktop I guess I can understand the worry.

If you really do have a good reason to think about it, this may be tied to the garbage collection algorithm you are using. Some algorithms will release unused memory back to the OS, some will not. There are some graphs and such related to this at http://www.stefankrause.net/wp/?p=14 . You might want to try the G1 collector, as it seems to release memory back to the OS easily.

Edit from comments What if they all choose to max their load at once? Are you ok with some of them paging memory to disk and slowing the server to a crawl? I would run them on a server with enough memory to run ALL applications at max heap, + another 4-6GB for the OS / caching. Servers with 32 or 64 GB are pretty common, and you can get more.

这篇关于在Java中调整垃圾收集参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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