Java Concurrent and Parallel GC

2019-01-30 00:28发布

This article here suggests to use -XX:+UseParNewGC "To enable a parallel young generation GC with the concurrent GC".

My confusion is that in order to enable both parallel and concurrent GC, should I

  • use -XX:+UseParNewGC or
  • use both -XX:+UseParNewGC and -XX:+UseConcMarkSweepGC ?

PS

I am using JVM 6.

6条回答
戒情不戒烟
3楼-- · 2019-01-30 01:02

You cannot enable two GC options at the same time. I would suggest you to use CMS which is better than and next generation GC compare to UseParNewGC. and if you use Java 1.7 or later and heap size is relatively bigger (like > 4GB) consider using G1.

查看更多
The star\"
4楼-- · 2019-01-30 01:11

This blog entry has a nice breakdown of the different collectors, and which options are valid: http://blogs.oracle.com/jonthecollector/entry/our_collectors

查看更多
做个烂人
5楼-- · 2019-01-30 01:13

Since the document you linked was for a 1.4.2 VM that's what I'll assume you're using (JVMs 5 and 6 behave differently).

From http://java.sun.com/docs/hotspot/gc1.4.2/

if -XX:+UseConcMarkSweepGC is used on the command line then the flag UseParNewGC is also set to true if it is not otherwise explicitly set on the command line

So the answer is you only need to use -XX:+UseConcMarkSweepGC and it will enable the concurrent collector with the parallel young generation collector.

Edit: for Java 6, the same flag (-XX:+UseConcMarkSweepGC) enables the concurrent collector. The choice of collector you want depends on a few things, and you should test different configurations. But there are some very general guidelines. If you have a single processor, single thread machine then you should use the serial collector (default for some configurations, can be enabled explicitly for with -XX:+UseSerialGC). For multiprocessor machines where your workload is basically CPU bound, use the parallel collector. This is enabled by default if you use the -server flag, or you can enable it explicitly with -XX:+UseParallelGC. If you'd rather keep the GC pauses shorter at the expense of using more total CPU time for GC, and you have more than one CPU, you can use the concurrent collector (-XX:+UseConcMarkSweepGC). Note that the concurrent collector tends to require more RAM allocated to the JVM than the serial or parallel collectors for a given workload because some memory fragmentation can occur.

查看更多
成全新的幸福
6楼-- · 2019-01-30 01:15

Java GC tuning is basically a dark art, but in my application (runs with a 50+GB heap, and 16 physical cores) the ConcMarkSweep collector resulted in a 3x speedup over the -server default, and a 2.2x speedup over ParallelOldGC.

If you aren't sharing the machine with other processes (so idle cores are just wasted) use the ConcMarkSweepGC.

查看更多
放荡不羁爱自由
7楼-- · 2019-01-30 01:24

ParNew is the default young generation collector when CMS is used.You just have to specify -XX:+UseConcMarkSweepGC to use CMS and ParNew will be used by default. CMS is a good collector if avoiding GC jitters is of higher priority but if throughput is more important for eg for a batch like job the default SUN parallel collector does a better job.

查看更多
登录 后发表回答