JVM optimization Summary (6)-generation Garbage Collection details 2

Source: Internet
Author: User
Generation-based garbage collection process to select an appropriate garbage collection Algorithm

Serial collectorProcessing all garbage collection tasks with a single thread is highly efficient because multi-thread interaction is not required. However, the advantages of multi-processor cannot be used, so this collector is suitable for single-processor machines. Of course, this collector can also be usedSmall data volume (about MB)In the case of a multi-processor machine. Available-XX: + useserialgcOpen.Parallel collector

Parallel garbage collection for young generation can reduce the garbage collection time. Generally used on multi-threaded Multi-processor machines. Use-XX: + useparallelgc.Open. The parallel collector is introduced in the sixth update of j2se5.0 and is enhanced in Java se6.0-parallel collection can be performed on older generations. If the old generation does not use concurrent collection, the single thread is used by default for garbage collection, which restricts the scalability. Use-XX: + useparalleloldgcOpen.

Use-XX: parallelgcthreads = <n>Sets the number of parallel garbage collection threads. This value can be set to be equal to the number of machine processors.

This collector can be configured as follows:

Maximum garbage collection pause:Specifies the maximum pause time for garbage collection.-XX: maxgcpausemillis = <n>. <N> millisecond. If this value is specified, the heap size and garbage collection parameters are adjusted to reach the specified value. Setting this value may reduce the application throughput.

Throughput:The throughput is the ratio of the garbage collection time to the non-garbage collection time.-XX: gctimeratio = <n>The formula is 1/(1 + n ). For example, when-XX: gctimeratio = 19, it indicates that 5% of the time is used for garbage collection. The default value is 99, that is, 1% of the time is used for garbage collection.

Concurrent collectorIt can ensure that most of the work is performed concurrently (the application does not stop), and garbage collection only suspends a small amount of time. This collector is suitable for medium and large scale applications with high response time requirements. Use-XX: + useconcmarksweepgcOpen.

Concurrent collectorMainReduce the pause time of the old generationWhen the application does not stop, it uses an independent garbage collection thread to track reachable objects. In each old generation garbage collection cycle, concurrent collectors at the beginning of collection
The entire application will be briefly paused and paused again during collection. The second pause will be a little longer than the first one. In this process, multiple threads perform garbage collection at the same time.

The concurrent collector uses a processor for a short pause. In a system with N processors, the concurrent collection part is recycled using k/N available processors. Generally, 1 <= k <= N/4.

When the concurrent collector is used on a host with only one processor, you can set it to the incremental mode to get a short pause time.

Floating garbage:Because the application is running at the same time for garbage collection, some garbage may be generated when the garbage collection is completed, resulting in "floating
Garbage ", the garbage can be recycled only in the next garbage collection cycle. Therefore, the concurrent collector generally requires 20% of the reserved space for these floating spam.Concurrent mode failure:The concurrent collector collects data when the application is running. Therefore, you must ensure that the heap has enough space for the program during the garbage collection period. Otherwise, the garbage collection is not completed and the heap space is full. In this case, "concurrent mode failure" will occur, and the entire application will be paused for garbage collection.
Start the concurrent COLLECTOR:Because concurrent collection is collected during application running, you must ensure that there is sufficient memory space for the program to use before the collection is complete. Otherwise"Concurrent
Mode failure"
. Set-XX: cmsinitiatingoccupancyfraction = <n>Specify the number of remaining heaps to start concurrent collection

Summary

Serial processor:

-- Applicability: applications with a small data volume (about MB) and a single processor that have no requirements for response time.
-- Disadvantage: it can only be used for small applications

 

Parallel processor:

-- Applicability: medium and large applications with high throughput requirements, multiple CPUs, and no application response time requirements. Example: background processing and scientific computing.
-- Disadvantage: application response time may be extended during garbage collection.

 

Concurrent processor:

-- Applicability: medium and large applications with high requirements on response time, multiple CPUs, and high requirements on application response time. Example: Web server/application server, telecom exchange, and integrated development environment.

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.