Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of Java garbage collection tuning

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what is the method of Java garbage collection tuning". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the method of Java garbage collection tuning".

It is important that performance tuning goals are identifiable and measurable. These goals include latency, throughput, and capacity, and for more information, I recommend taking a look at the corresponding sections in the garbage Collection Manual (Garbage Collection Handbook). Let's look at how to set and achieve such tuning goals in practice. To this end, let's look at a sample code:

/ / imports skipped for brevity public class Producer implements Runnable {private static ScheduledExecutorService executorService = Executors.newScheduledThreadPool (2); private Deque deque; private int objectSize; private int queueSize; public Producer (int objectSize, int ttl) {this.deque = new ArrayDeque (); this.objectSize = objectSize; this.queueSize = ttl * 1000;} @ Override public void run () {for (int I = 0; I)

< 100; i++) { deque.add(new byte[objectSize]); if (deque.size() >

QueueSize) {deque.poll ();} public static void main (String [] args) throws InterruptedException {executorService.scheduleAtFixedRate (new Producer (1024 * 1024 / 1000, 5), 0100, TimeUnit.MILLISECONDS); executorService.scheduleAtFixedRate (new Producer (50 * 1024 * 1024 / 1000), 0100, TimeUnit.MILLISECONDS); TimeUnit.MINUTES.sleep (10); executorService.shutdownNow ();}}

Two jobs (job) are submitted in the code and run once per 100ms. Each job simulates the life cycle of a particular object: first create objects, let them "live" for a while, then forget them and let GC reclaim memory. When running this example, open the GC log and use the following parameters:

-XX:+PrintGCDetails-XX:+PrintGCDateStamps-XX:+PrintGCTimeStamps

We immediately see in the log file the impact of GC similar to the following:

2015-06-04T13:34:16.119-0200: 1.723: [GC (Allocation Failure) [PSYoungGen: 114016K-> 73191K (234496K)] 421540K-> 421269K (745984K), 0.0858176 secs] [Times: user=0.04 sys=0.06, real=0.09 secs] 2015-06-04T13:34:16.738-0200: 2.342: [GC (Allocation Failure) [PSYoungGen: 234462K-> 93677K (254976K)] 582540K-> 593275K (766464K), 0.2357086 secs] [Times: user=0.11 sys=0.14 Real=0.24 secs] 2015-06-04T13:34:16.974-0200: 2.578: [Full GC (Ergonomics) [PSYoungGen: 93677K-> 70109K (254976K)] [ParOldGen: 499597K-> 511230K (761856K)] 593275K-> 581339K (1016832K), [Metaspace: 2936K-> 2936K (1056768K)], 0.0713174 secs] [Times: user=0.21 sys=0.02, real=0.07 secs]

Based on the information in the log, we can start to improve performance. And keep in mind three different goals:

Make sure that the worst-case scenario of GC pause (garbage collection pause) does not exceed the expected threshold.

Ensure that the application thread stagnation time does not exceed a predetermined threshold.

Reduce infrastructure costs while ensuring that we can still achieve reasonable latency and throughput targets.

To this end, it was run for 10 minutes in each of three different configurations, and three results with large gaps are summarized in the following table:

Heap

GC algorithm

Work effectively

Long pause

-Xmx12g

-XX:+UseConcMarkSweepGC

89.8%

560 ms

-Xmx12g

-XX:+UseParallelGC

91.5%

1104 ms

-Xmx8g

-XX:+UseConcMarkSweepGC

66.3%

1610 ms

In the experiment, set different GC algorithms and different heap sizes, run the same code, and then measure the duration and throughput of garbage collection pauses. The details of the experiment and the explanation of the results are in our garbage collection manual. Looking at some examples in the manual, modifying some simple configurations results in completely different performance in terms of latency, throughput, and so on.

Note: to keep the example as simple as possible, only a limited number of input parameters have been changed, such as not testing different number of cores (CPU core) or different heap layouts.

Thank you for your reading, the above is the content of "what is the method of Java garbage collection tuning". After the study of this article, I believe you have a deeper understanding of what the method of Java garbage collection tuning is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report