JVM Optimization-Initialize space size Configuration

Source: Internet
Author: User

JVM Optimization-Initialize space size Configuration

We get the active data size, and we can configure our initialization space based on the active data.

Below is a full GC of our application in the stable phase. The generated code is at the end.

1. Example of Active Data

[Full GC [PSYoungGen: 64 K-> 0 K (4416 K)] [PSOldGen: 51352 K-> 51352 K (56768 K)] 51416 K-> 51352 K (61184 K) [PSPermGen: 2085 K-> 2085 K (12288 K)], 0.0026228 secs] [Times: user = 0.00 sys = 0.00, real = 0.00 secs]

PSYoungGen: New Generation

PSOldGen: in the old age, the occupied space is 51352 kb and 51 mb. This is the active data of the old age.

PSPermGen: Permanent band. It occupies 2085 kb and 2 MB. It is the active data size of permanent band.

2. Common empirical parameters

2.1 age

The initialization value and maximum value of the Java heap size (specified by the-Xms and-Xmx options) should be three to four times the size of the active object in the old age.

The GC record above shows that the size of the old generation is 51 MB, so the corresponding initial value and maximum value are between 153M and 204M;-Xms153m-Xmx204M

2.2 permanent generation size

Another general rule is that the initial value and maximum value (-XX: PermSize and-XX: MaxPermSize) of permanent tape must be 1.2 to 1.5 times the size of permanent active objects. After FullGC, the permanent occupied space is 2 MB. Therefore, the recommended permanent generation size is 2.4M to 3 M, that is, it can be set to-XX: PermSize = 3m-XX: MaxPermSize = 3 m (1.5 times ).

2.3 New Generation

The new generation space should be 1 to 1.5 times the size of the active objects in the old age. In this example, the size of the new generation can be set to 51 MB to 76 MB.

Then the final parameter is:-Xms200m-Xmx200m-Xmn60m-XX: PermSize = 3 m-XX: MaxPermSize = 3 m-XX: + UseParallelGC-XX: + PrintGCDetails

After use, FULLGC will no longer appear, and there will be no memory overflow issues.

3. Calculate the source code of Active Data (simulate full gc)

Packagecom. gc;

Importjava. util. ArrayList;

Importjava. util. List;

/**

* A simple FULLGC simulation is used to calculate the active data size.

* Parameter:-Xms30m-Xmx60m-XX: + UseParallelGC-XX: + PrintGCDetails

* @ Author fan fangming

*/

Publicclass EasyActiveData {

Public byte [] placeHolder = new byte [1024*1024]; // placeHolder 1 M

Public static void main (String [] args) throws Exception {

ActiveData ();

}

Private static void activeData () throwsException {

List <EasyActiveData> list_a = new ArrayList <EasyActiveData> ();

List <EasyActiveData> list_ B = new ArrayList <EasyActiveData> ();

For (int j = 0; j <25; j ++ ){

EasyActiveDataserial = new EasyActiveData ();

List_a.add (serial );

}

Thread. sleep (100); // pause

For (int j = 0; j <30; j ++ ){

EasyActiveDataserial = new EasyActiveData ();

List_ B .add (serial );

}

Thread. sleep (100); // pause

While (true ){

EasyActiveDataserial = new EasyActiveData ();

Serial = list_a.get (0 );

Serial = null;

Serial = list_ B .get (0 );;

Thread. sleep (100); // pause for 10 ms

}

}

}

Running Parameters

-Xms30m startup memory

-Xmx60m maximum memory

-XX: + UseParallelGC: Garbage collection method selected

-XX: + PrintGCDetails: Print GC details

4. Running result

...

[Full GC [PSYoungGen: 64 K-> 0 K (4416 K)] [PSOldGen: 51352 K-> 51352 K (56768 K)] 51416 K-> 51352 K (61184 K) [PSPermGen: 2085 K-> 2085 K (12288 K)], 0.0026228 secs] [Times: user = 0.00 sys = 0.00, real = 0.00 secs]

[GC [PSYoungGen: 4098 K-> 48 K (4416 K)] 55450 K-> 55496 K (61184 K), 0.0038392 secs] [Times: user = 0.00 sys = 0.00, real = 0.00 secs]

[Full GC [PSYoungGen: 48 K-> 0 K (4416 K)] [PSOldGen: 55448 K-> 55448 K (56768 K)] 55496 K-> 55448 K (61184 K) [PSPermGen: 2085 K-> 2085 K (12288 K)], 0.0025522 secs] [Times: user = 0.02 sys = 0.00, real = 0.00 secs]

[Full GC [PSYoungGen: 4098 K-> 0 K (4416 K)] [PSOldGen: 55448 K-> 56472 K (56768 K)] 59546 K-> 56472 K (61184 K) [PSPermGen: 2085 K-> 2085 K (12288 K)], 0.0043092 secs]

...

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.