JVM tuning-calculate the active data size and jvm tuning Active Data

Source: Internet
Author: User

JVM tuning-calculate the active data size and jvm tuning Active Data


Active Data, sometimes called survival data, refers to the size of long-lived objects in the Java heap when the application is in stable running state. In other words, the space occupied by the Java heap after FullGC in the stable running state of the application (memory usage ).

1. Importance of active data computing

The calculation of the active data size of Java applications is an essential process for JVM optimization. If we do not know the number of active data in this system, how can we allocate suitable memory to him? Therefore, calculating the size of active data is an important step for JVM optimization.

The active data size of Java applications can be collected by GC logs.

Active Data mainly includes two parts: the size of the Old Age and the size of the permanent generation.

2. View Active Data

In order to better calculate the active data size of the application, it is best to check the usage of the JAVA heap after multiple FULLGC operations. But again, many JVMs may encounter a large number of full gc attacks due to unreasonable memory settings. if this data is used to guide optimization, the more debugging, the more chaotic the cycle;

At the same time, some systems have been optimized or run into good luck. If you set a parameter, the result is just right. FULLGC has never happened, full gc is hardly visible when GC logs are collected. In this case, you can use some tools to force garbage collection and trigger the FULLGC event. For example, use the JConsole that comes with JDK to trigger the call.

Computing active data is the core of JVM optimization.

First, let's take a look at the example. It is easier to find full gc in practical application, but it is troublesome to move the entire system. Write a simple example to simulate the situation of FULLGC.

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 = newbyte [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: 48 K-> 0 K (4416 K)] [PSOldGen: 30879 K-> 30879 K (39488 K)] 30927 K-> 30879 K (43904 K) [PSPermGen: 2086 K-> 2086 K (12288 K)], 0.0028453 secs] [Times: user = 0.00 sys = 0.00, real = 0.00 secs]

[GC [PSYoungGen: 4098 K-> 48 K (4416 K)] 34977 K-> 35023 K (43904 K), 0.0035403 secs] [Times: user = 0.00 sys = 0.00, real = 0.00 secs]

[Full GC [PSYoungGen: 48 K-> 0 K (4416 K)] [PSOldGen: 34975 K-> 34975 K (44672 K)] 35023 K-> 34975 K (49088 K) [PSPermGen: 2086 K-> 2086 K (12288 K)], 0.0026413 secs] [Times: user = 0.00 sys = 0.00, real = 0.00 secs]

[GC [PSYoungGen: 4098 K-> 48 K (4416 K)] 39073 K-> 39119 K (49088 K), 0.0028593 secs] [Times: user = 0.00 sys = 0.06, real = 0.00 secs]

[GC [PSYoungGen: 4146 K-> 48 K (4416 K)] 43217 K-> 43219 K (49088 K), 0.0035522 secs] [Times: user = 0.00 sys = 0.00, real = 0.00 secs]

[Full GC [PSYoungGen: 48 K-> 0 K (4416 K)] [PSOldGen: 43171 K-> 43152 K (54272 K)] 43219 K-> 43152 K (58688 K) [PSPermGen: 2086 K-> 2085 K (12288 K)], 0.0086702 secs] [Times: user = 0.00 sys = 0.00, real = 0.01 secs]

[GC [PSYoungGen: 4098 K-> 64 K (4416 K)] 47250 K-> 47312 K (58688 K), 0.0032439 secs] [Times: user = 0.00 sys = 0.06, real = 0.00 secs]

[GC [PSYoungGen: 4162 K-> 64 K (4416 K)] 51410 K-> 51416 K (58688 K), 0.0049324 secs] [Times: user = 0.00 sys = 0.00, real = 0.00 secs]

[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.00sys = 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]

...

 

 

5. Result Analysis and Calculation of active data size

[Full GC [PSYoungGen: 48 K-> 0 K (4416 K)] [PSOldGen: 43171 K-> 43152 K (54272 K)] 43219 K-> 43152 K (58688 K) [PSPermGen: 2086 K-> 2085 K (12288 K)], 0.0086702 secs] [Times: user = 0.00 sys = 0.00, real = 0.01 secs]

[GC [PSYoungGen: 4098 K-> 64 K (4416 K)] 47250 K-> 47312 K (58688 K), 0.0032439 secs] [Times: user = 0.00 sys = 0.06, real = 0.00 secs]

[GC [PSYoungGen: 4162 K-> 64 K (4416 K)] 51410 K-> 51416 K (58688 K), 0.0049324 secs] [Times: user = 0.00 sys = 0.00, real = 0.00 secs]

[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]

It can be seen from this that the old age is gradually expanding.

[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]

After this data is obtained, the space occupied by the old age is approximately 51352 K, and the size of the old age is basically 56768 K. The permanent bandwidth occupies 2085 KB of space and the size is 12288 kb.

Therefore, the active data size of this program is: 51352 K + 2085K is approximately 55 M

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.