Java garbage Collector's parallel scavenge collector

Source: Internet
Author: User


Parallel Scavenge collectors are JAVA one of the garbage collectors in a virtual machine. similar to the Parnew collector, it is a new generation collector. A parallel multithreaded collector using the replication algorithm.

1 , features

Parallel ScavengeThe collector's focus is different from other collectors,ParallelscavengeThe target of the collector is to achieve a controllable throughput (Throughput). The so-called throughput isCPUthe time used to run user code isCPUthe ratio of total time consumed, i.e. throughput = Run user code time /(run user code time +garbage collection Time), the virtual machine runs in total -minutes, where the garbage collection was spent1minutes, that throughput is99%.

due to the close relationship with throughput, Parallel Scavenge collectors are also often referred to as "throughput first" collectors.

The garbage collector, which is the default value of the JAVA virtual machine in server mode, after using server mode, Java virtual machine uses Parallel scavenge Collector (Cenozoic)+ Serial old Collector (old age) collection of collectors for memory recycling.

2 , usage Scenarios

The main adaptation is primarily for tasks that work in the background and do not require too much interaction.

For example, the program that needs to interact with the user, the good response speed can improve the user's experience, and the high throughput can make the most efficient use of CPU time, as soon as possible to complete the operation of the program tasks.

3 , Important parameters

important parameters are three, of which two parameters are used to precisely control throughput, respectively, to control the maximum garbage collection pause time -xx:maxgcpausemillis parameters and directly set the throughput size -xx:gctimeratio parameters. The other one is the useadaptivesizepolicy switch parameter.

Maxgcpausemillisparameter allows a value that is greater than0number of milliseconds, the collector will try to ensure that the memory recovery takes no longer than the set value. But let's not be ridiculous to think that if you set the value of this parameter a little bit, you can make the system garbage collection faster .GCthe shortening of the pause time is exchanged for the sacrifice of throughput and the new generation of space: The system reduces the Cenozoic and collects300MBThe new generation certainly better than collecting500MBquickly, it also leads to garbage collection happening more frequently, the originalTenseconds to collect, every pause -milliseconds, and now becomes5seconds to collect, every pause -milliseconds. The pause time is indeed falling, but the throughput is lowered.

Gctimeratiothe value of the parameter should be a greater than0less than -Integer, which is the ratio of garbage collection time to total time, is equivalent to the reciprocal of the throughput. If you set this parameter to +, that allowed the largestGCtime is the total time.5%(i.e.1/(1+19) ), the default value is About, is to allow the maximum1%(i.e.1/(1+99) for garbage collection time.

-xx:+useadaptivesizepolicy -xmn eden survivor -xx:survivorratio -xx:pretenuresizethreshold Span style= "Color:rgb (51,51,51)" >GC Adaptive Tuning strategy ( GC ergonomics

4 , adaptive adjustment Strategy

Parallel Scavenge The collector is able to adapt the memory management tuning task to the virtual machine to complete with adaptive adjustment strategy. Just set the basic memory data (such as -xmx to set the maximum heap), then use the maxgcpausemillis parameter (more attention to maximum pause time) or The Gctimeratio parameter (more focused on throughput) sets an optimization target for the virtual machine, and the tuning of the specific details parameter is done by the virtual machine. The adaptive Tuning strategy is also an important difference between the Parallel scavenge collector and the parnew collector.

5 , specific use examples

Source

Package COM.GC;

Import java.util.ArrayList;

Import java.util.List;

/**

 * simple. JAVA Virtual machine Memory Reclamation , Parallel scavenge Use of Collectors

 * operating parameters, see specific methods, note: Need to open Server mode to use

* @author Fan Fangming

*/

public class Easyparallelscavenge {

Public byte[] PlaceHolder =new byte[64 * 1024x768];// placeholder

public static Voidmain (string[] args) throws exception{

Outofmemorybyexpansionsize ();

}

/**

* JAVA the size of the virtual machine can be scaled appropriately, where xms30m , xmx400m

        * Parameters: -server-xms30m-xmx100m-xx:+useparallelgc-xx:+printgcdetails

* @author Fan Fangming

*/

private static Voidoutofmemorybyexpansionsize () throws exception{

List<easyparallelscavenge>list = new arraylist<easyparallelscavenge> ();

while (true) {

easyparallelscavengeserial = new Easyparallelscavenge ();

List.add (serial);

Thread.Sleep (Ten);// Pause Ten milliseconds

}

}

}

Parameter description:

-server Server mode Operation

-xms30m Minimum JAVA Virtual Machine Memory 30M

-xmx100m Maximum JAVA Virtual Machine Memory 100M

-XX:+USEPARALLELGC explicitly specify the use Parallel Scavenge Collecting Device

-xx:+printgcdetails Print Recovery Status

The results of the operation are as follows:

... .. [GC [psyounggen:7449k->3728k (7552K)] 66980k->66980k (75136K), 0.0022792 secs] [times:user=0.00 sys=0.00, real=0.00 secs]

[GC [psyounggen:7443k->3728k (7552K)] 70695k->70715k (75136K), 0.0027722 secs] [times:user=0.00 sys=0.03, real=0.00 secs]

[Full GC [psyounggen:3728k->3136k (7552K)] [psoldgen:66986k->67563k (76928K)]70715k->70700k (84480K) [ pspermgen:2088k->2088k (16384K)], 0.0038774 secs][times:user=0.00 sys=0.00, real=0.00 secs]

[GC [psyounggen:3714k->3744k (7552K)]71278k->71308k (84480K), 0.0017028 secs] [times:user=0.00 sys=0.00,real=0.00 secs]

[GC [Psyounggen:7459k->3744k (7552K)] 75023k->75025k (84480K), 0.0027427 secs] [times:user=0.00 sys=0.00, real=0.00 secs]

[GC [psyounggen:7459k->3744k (7552K)]78739k->78753k (84480K), 0.0048844 secs] [times:user=0.03 sys=0.00,real=0.01 secs]

[Full GC [psyounggen:3744k->1728k (7552K)] [psoldgen:75009k->76922k (87488K)]78753k->78651k (95040K) [ pspermgen:2088k->2088k (16384K)], 0.0107597 secs][times:user=0.00 sys=0.00, real=0.01 secs]

[GC [Psyounggen:3714k->3744k (7552K)] 80637k->80667k (95040K), 0.0015904 secs] [times:user=0.00 sys=0.00, real=0.00 secs]

[GC [psyounggen:7459k->3728k (7552K)] 84382k->84372k (95040K), 0.0028244 secs] [times:user=0.03 sys=0.00, real=0.00 secs]

[GC [psyounggen:7443k->3728k (7552K)] 88087k->88093k (95040K), 0.0023412 secs] [times:user=0.00 sys=0.00, real=0.00 secs]

[Full GC [psyounggen:3728k->640k (7552K)] [psoldgen:84364k->87438k (91072K)]88093k->88078k (98624K) [ pspermgen:2088k->2088k (16384K)], 0.0048474 secs][times:user=0.00 sys=0.00, real=0.00 secs]

[Full GC [psyounggen:3714k->128k (7552K)] [psoldgen:87438k->91023k (91072K)]91153k->91151k (98624K) [ pspermgen:2088k->2088k (16384K)], 0.0047349 secs][times:user=0.00 sys=0.00, real=0.00 secs]

[Full GC [psyounggen:3714k->3714k (7552K)] [psoldgen:91023k->91023k (91072K)]94738k->94738k (98624K) [ pspermgen:2088k->2088k (16384K)], 0.0031963 secs][times:user=0.00 sys=0.00, real=0.00 secs]

[Full GC [psyounggen:3714k->3649k (7552K)][psoldgen:91023k->91070k (91072K)] 94738k->94720k (98624K) [ pspermgen:2088k->2087k (16384K)], 0.0209529 secs] [times:user=0.03 sys=0.00, Real=0.02secs]

[Full GC [psyounggen:3713k->3713k (7552K)] [psoldgen:91070k->91070k (91072K)] 94784k->94784k (98624K) [ pspermgen:2087k->2087k (16384K)], 0.0035128 secs] [times:user=0.02sys=0.00, real=0.00 secs]

[Full GC [psyounggen:3713k->3713k (7552K)] [psoldgen:91070k->91070k (91072K)]94784k->94784k (98624K) [ pspermgen:2087k->2087k (16384K)], 0.0027033 secs][times:user=0.00 sys=0.00, real=0.00 secs]

Exception in thread "main" Java.lang.OutOfMemoryError:Java heap space

atcom.gc.easyparnew.<init> (easyparnew.java:12)

atcom.gc.EasyParNew.outOfMemoryByExpansionSize (easyparnew.java:39)

Atcom.gc.EasyParNew.main (easyparnew.java:14)

Heap

Psyounggen total 7552K, used 3776K [0x0e4b0000, 0x0efc0000, 0x0efc0000)

Eden Space 3776K, 100% used [0x0e4b0000,0x0e860000,0x0e860000)

From space 3776K, 0% used [0x0ec10000,0x0ec10000,0x0efc0000)

To space 3776K, 0% used[0x0e860000,0x0e860000,0x0ec10000)

Psoldgen total 91072K, used 91070K [0x08bc0000, 0x0e4b0000, 0x0e4b0000)

Object Space 91072K, 99% used[0x08bc0000,0x0e4af980,0x0e4b0000)

6 , and Serial , parnew simple differences between two types of new generation collectors

[GC [defnew:1986k->128k (2112K), 0.0011191 secs] 27809k->27808k (30528K), 0.0011425 secs] [times:user=0.00sys=0.01, real=0.00 secs]

And

[GC [Parnew:1990k->132k (2112K), 0.0007742 secs] 24112k->24110k (30528K), 0.0007964 secs] [times:user=0.00sys=0.00, real=0.00 secs]

And

[GC [psyounggen:7449k->3728k (7552K)] 66980k->66980k (75136K), 0.0022792 secs] [times:user=0.00 sys=0.00, real=0.00 secs]

Gc[parnew indicates that the Parnew collector is being used.

Gc[defnew indicates that the serial collector is used.

[Gc[psyounggen indicates that the parallel scavenge collector is used.

Java garbage Collector's parallel scavenge collector

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.