问题描述
我在 64 位 Linux 上运行一个应用服务器,它有 8 个核心 CPU 和 6 GB 内存.
I am running an application server on Linux 64bit with 8 core CPUs and 6 GB memory.
服务器必须高度响应.
经过一番检查,我发现在服务器上运行的应用程序创建了相当大量的短期对象,并且只有大约 200~400 MB 的长期对象(只要没有内存泄漏)
After some inspection I found that the application running on the server creates rather a huge amount of short-lived objects, and has only about 200~400 MB long-lived objects(as long as there is no memory leak)
看完http://java.sun.com/javase/技术/热点/gc/gc_tuning_6.html我使用这些 JVM 选项
After reading http://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.html I use these JVM options
-server -Xms2g -Xmx2g -XX:MaxPermSize=256m -XX:NewRatio=1 -XX:+UseConcMarkSweepGC
结果:minor GC 需要 0.01 ~ 0.02 sec,major GC 需要 1 ~ 3 sec次要 GC 不断发生.
Result: the minor GC takes 0.01 ~ 0.02 sec, the major GC takes 1 ~ 3 sec the minor GC happens constantly.
如何进一步改进或调整 JVM?
How can I further improve or tune the JVM?
更大的堆大小?但是GC会需要更多时间吗?
larger heap size? but will it take more time for GC?
更大的 NewSize 和 MaxNewSize(针对年轻一代)?
larger NewSize and MaxNewSize (for young generation)?
其他收藏家?并行GC?
other collector? parallel GC?
让major GC更频繁地发生是个好主意吗?以及如何?
is it a good idea to let major GC take place more often? and how?
推荐答案
结果:minor GC 需要 0.01 ~ 0.02 sec,major GC 需要 1 ~ 3 sec,minor GC 不断发生.
Result: the minor GC takes 0.01 ~ 0.02 sec, the major GC takes 1 ~ 3 sec the minor GC happens constantly.
除非您报告暂停,否则我会说 CMS 收集器正在执行您要求它执行的操作.根据定义,CMS 将使用比串行和并行收集器更大百分比的 CPU.这是您为低暂停时间付出的代价.
Unless you are reporting pauses, I would say that the CMS collector is doing what you have asked it to do. By definition, CMS will use a larger percentage of the CPU than the Serial and Parallel collectors. This is the penalty you pay for low pause times.
如果您看到 1 到 3 秒 暂停 次,我会说您需要进行一些调整.我不是专家,但看起来您应该从默认值 92 减少 CMSInitiatingOccupancyFraction
的值开始.
If you are seeing 1 to 3 second pause times, I'd say that you need to do some tuning. I'm no expert, but it looks like you should start by reducing the value of CMSInitiatingOccupancyFraction
from the default value of 92.
增加堆大小将提高 GC 的吞吐量".但如果您的问题是长时间停顿,那么增加堆大小可能会使问题变得更糟.
Increasing the heap size will improve the "throughput" of the GC. But if your problem is long pauses, increasing the heap size is likely to make the problem worse.
这篇关于为高响应服务器应用程序调整 JVM (GC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!