What is the fastest Garbage Collector in Java 8?

Source: Internet
Author: User

What is the fastest Garbage Collector in Java 8?

OpenJDK 8 has multiple GCGarbage Collector) algorithms, such as Parallel GC, CMS, and G1. Which one is the fastest? What if I change the default GC of Java 8 from Parallel GC to G1 in Java 9? Let's perform a benchmark test on this.

Benchmarking Method

Run the same code six times and use different VM parameters-XX: + UseSerialGC,-XX: + UseParallelGC,-XX: + UseConcMarkSweepGC,-XX: ParallelCMSThreads = 2,-XX: parallelCMSThreads = 4,-XX: + UseG1GC ).

It takes about 55 minutes to run each time.

Other VM parameters:-Xmx2048M-server

OpenJDK version: 1.8.0 _ 51 Latest Version)

Software: Linux version 4.0.4-301. fc22.x86 _ 64

Hardware: Intel? Core? I7-4790 CPU @ 3.60 GHz

13? OptaPlanner? Plan the problem plan. The running time is 5 minutes. The first 30 seconds are used for JVM push, not included.

To solve the planning problem, I/O is not involved except that it takes several milliseconds to load the input information at startup ). A single CPU is completely saturated. Many objects with short survival time are usually created, which will be recycled after GC.

The measurement criterion is to calculate the score per millisecond. The higher the score, the better. Computing a proposed Planning solution is a major problem: it involves a large number of computations, including detection of conflicts between each entity and all other entities.

To repeat these benchmark tests locally, you can build them from the source code and then run the main class GeneralOptaPlannerBenchmarkApp.

Benchmark Test Results

Execution result

For ease of viewing, I have compared each GC with the default GCParallel GC in Java 8.

The results are clear:By default, Parallel GC is the fastest..

Raw Benchmark Test Data

Relative Benchmark Test Data

Should Java 9 be G1 by default?

One proposal is to use G1 as the default GC on the OpenJDK9 server. My first response was to reject the proposal:

The average value of G1 is 17.60% slower.

G1 is slow in each dataset case.

In the largest data set Machine Reassignment B10), the performance is worse than other data sets, and G1 is 34.07% slower.

If different default GC is used between the development machine and the server, the reliability of the developer benchmark test will decrease.

On the other hand, there are several details to be aware:

G1 focuses on GC pause rather than throughput. For these cases, the GC pause duration is basically not affected.

This is basically a single-thread benchmark test. Benchmark tests that solve multiple problems in parallel or use multiple threads may have different results.

The recommended heap memory for G1 is at least 6 GB. The heap memory for this benchmark test is 2 GB, so that only so much memory is needed even in the maximum dataset Machine Reassignment B10.

Massive computing is only one of the many functions of OpenJDK: This is a widely debated issue in the community. If there are other aspects such as website services), it may be worth changing the default GC. However, first show me the benchmark test for your actual project.

Conclusion

In Java 8, for OptaPlanner use cases, GCParallel GC by default) is usually the best choice.

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.