JVM更高的分配率会对性能产生影响吗?怎么样

时间:2017-12-27 22:53:04

标签: java garbage-collection jvm

使用-Xmx32m的GC日志如下:

808: [GC (Allocation Failure) [PSYoungGen: 9760K->32K(10240K)], 0.0003076 secs]
819: [GC (Allocation Failure) [PSYoungGen: 9760K->32K(10240K)], 0.0003079 secs]
830: [GC (Allocation Failure) [PSYoungGen: 9760K->32K(10240K)], 0.0002968 secs



2nd Allocation rate is (9760-32)/(819-808)= 884.36K
3rd Allocation rate is (9760-32)/(830-819)= 884.36K

使用-Xmx64m的GC日志如下:

808: [GC (Allocation Failure) [PSYoungGen: 20512K->32K(20992K)], 0.0003748 secs]
831: [GC (Allocation Failure) [PSYoungGen: 20512K->32K(20992K)], 0.0004538 secs]
855: [GC (Allocation Failure) [PSYoungGen: 20512K->32K(20992K)], 0.0003355 secs]

2nd allocation rate is (20512-32)/(831-808)=890.43K
3nd allocation rate is (20512-32)/(855-831)=853.33K

根据https://plumbr.io/handbook/gc-tuning-in-practicehttp://stuff-gil-says.blogspot.com/2014/10/what-sort-of-allocation-rates-can.html帖子,较低的分配率会更好。怎么样?

1 个答案:

答案 0 :(得分:1)

我不确定具体问题是什么。链接涵盖了主题。我将总结一下:

  1. 分配率会影响次要GC的频率。您分配的速度越快,您执行次要GC的频率就越高。要执行次要GC JVM必须使用一些CPU电源来查找未使用的对象并执行GC所做的其他操作。这意味着一些CPU电源将用于垃圾收集,而不是执行应用程序代码。有时,应用程序代码需要所有CPU能力才能处理负载,过于频繁的GC会对吞吐量产生负面影响。为了提高吞吐量,可以降低分配率,这将导致GC频率降低,并为流量处理留出更多CPU。

  2. 还存在与过早晋升有关的问题。高分配率可能导致频繁的次要GC,这意味着一些短的生命对象可能会被提升为老一代,因为它在少数几个小的GC中幸存下来。当较小的地方选区非常频繁,那么幸存下来的少数人并不意味着这个物体是长寿的。向老一代推广短生活对象将导致更频繁的主要GC。