Java 7 (Jdk 7) Garbage Collection and Documentation on G1

G1 slower than default garbage collector on Java 7

and noticed it takes more time to start an application

That has several reasons

First: In most cases the default collector is the parallel collector, also known as throughput collector. It is the most efficient one in terms of wall time spent in GC relative to wall time spent in application code.[1]. It does not have to bear the extra costs of performing concurrent work.

G1 primarily optimizes for lower pause times on large heaps by expending additional CPU cycles on partially concurrent collections, which requires that you have CPU cycles to spare. Throughput is only a secondary goal.

Second: enabling G1 changes more than the algorithm used, many default settings are also changed.

diff <(java -XX:+UseG1GC -XX:+PrintFlagsFinal) <(java -XX:+PrintFlagsFinal) shows how other flags are changed

On java 8 there are the following differences that significantly affect GC behavior, among several others:

<     uintx GCTimeRatio                               = 9                                   {product}
> uintx GCTimeRatio = 99 {product}
< uintx MaxGCPauseMillis = 200 {product}
> uintx MaxGCPauseMillis = 18446744073709551615 {product}

Third: Application startup is not exactly a good way to measure anything since that's a transient event and the heap still has to settle into its final size. Collectors aim for steady-state operation and may handle such transients differently.


On an "old RISC server" and a heap size of 128 MB you definitely want to stick to either the parallel or serial collectors. Such a configuration does not benefit from what G1 has to offer.

[1] For CPU cycles instead of wall time it would be the serial collector.

Why Garbage-First (G1) targeted for multiprocessor machines with large memories

It's other way around. G1 is not targeted for large memories. If your application demands large heap size, G1 is effective.

Why your application demands large heaps? It's depend on business requirements and specific needs of application. You may load huge set of master data Or you may use in - memory caching to reduce response times. Think of big data applications,(Spark,Hadoop) which are processing teta bytes of data and use memory for processing.

Multiprocessors machines have more processing powers and effective for parallel execution of different tasks. Large heap applications obviously demands more processing power.

By setting Max pause time goal, G1GC try to meet that goal. Compared to other algorithms, by default G1GC spends 10% of time in garbage collection activities. You have to fine tune the parameters properly to achieve your pause time goals.

This related question is helpful to get some more insight into G1GC: Java 7 (JDK 7) garbage collection and documentation on G1

Java G1 garbage collection in production

It sounds like the point of G1 is to have smaller pause times, even to the point where it has the ability to specify a maximum pause time target.

Garbage collection isn't just a simple "Hey, it's full, let's move everything at once and start over" deal any more--it's fantastically complex, multi-level, background threaded system. It can do much of its maintenance in the background with no pauses at all, and it also uses knowledge of the system's expected patterns at runtime to help--like assuming most objects die right after being created, etc.

I would say GC pause times are going to continue to improve, not worsen, with future releases.

EDIT:

in re-reading it occurred to me that I use Java daily--Eclipse, Azureus, and the apps I develop, and it's been a LONG TIME since I saw a pause. Not a significant pause, but I mean any pause at all.

I've seen pauses when I right-click on windows explorer or (occasionally) when I hook up certain USB hardware, but with Java---none at all.

Is GC still an issue with anyone?

What's the default GC for jdk1.7.0_11 on Windows and jdk1.7.0_17 on Linux?

From Garbage-First Collector :

The Garbage-First (G1) garbage collector is fully supported in Oracle
JDK 7 update 4 and later releases. The G1 collector is a server-style
garbage collector, targeted for multi-processor machines with large
memories. It meets garbage collection (GC) pause time goals with high
probability, while achieving high throughput. Whole-heap operations,
such as global marking, are performed concurrently with the
application threads. This prevents interruptions proportional to heap
or live-data size.

G1 is not default garbage collector in jdk 1.7. The default garbage collector depends upon whether it is java client vm or java server vm.



Related Topics



Leave a reply



Submit