In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about what the JVM parameters are and how to tune them. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
Basic concepts of tuning
There are usually three components to consider when tuning JVM performance:
Heap size adjustment
Garbage collector adjustment
JIT compiler
Most tuning options are related to resizing the heap and choosing the appropriate garbage collector, and the JIT compiler also has a significant impact on performance, but it rarely needs to be tuned, especially for newer versions of JVM.
In general, when tuning Java programs, you focus on two main metrics:
Responsiveness: the speed at which applications respond to requests. For responsive applications, long pauses are unacceptable and need to respond in the shortest possible time.
Throughput: focus on maximizing the workload of the application for a specific period of time, and for applications focused on throughput, a pause that meets the requirements is acceptable.
Whether JVM itself is constantly optimized, the core of the system bottleneck is still the application code, and more often, we should focus on the optimization of the application code.
Common JVM parameters
GC tuning idea
Analyze scenarios, such as slow startup, occasional slower than average response or stutter
Identify goals, such as memory footprint, low latency, throughput
Collect logs, such as collecting GC logs through parameter configuration, and viewing GC status through JDK tool
Analysis log, such as: use tools to assist analysis log, view GC times, GC time
Adjust parameters, such as switching garbage collectors or adjusting garbage collector parameters
Common GC parameters
Parameter tuning of garbage collector Parallel
The Parallel garbage collector is the default garbage collector for JVM in JDK8. It is a garbage collector that gives priority to throughput. The adjustable parameters are as follows:
Parameter tuning of garbage collector CMS
The CMS garbage collector is a response time first garbage collector. Consider using the CMS garbage collector when the Parallel collector cannot meet the application latency requirements. Starting with JDK9, the CMS collector is no longer recommended, and the G1 garbage collector is used by default.
Parameter tuning of garbage collector G1
The G1 collector is a collector that takes into account both throughput and response time. If it is a large heap (for example, the heap size exceeds 6GB), and the utilization of the heap exceeds 50%, the GC delay is required to be stable and predictable less than 0.5 seconds. It is recommended to use the G1 collector.
Tuning exampl
Sample code:
@ SpringBootApplication
Public class SpringBootDemoApplication {
Public static void main (String [] args) {
SpringApplication.run (SpringBootDemoApplication.class, args)
Executors.newScheduledThreadPool (1)
.accouneAtFixedRate (
()-> {
New Thread (
()-> {
For (int I = 0; I
< 150; i++) { try { byte[] temp = new byte[1024 * 512]; Thread.sleep(new Random().nextInt(1000)); } catch (InterruptedException e) { e.printStackTrace(); } } }) .start(); }, 100, 100, TimeUnit.MILLISECONDS); } } GC分析主要查看GC导致的Stop The World的时间,它会导致程序的延时增加。 示例代码运行的时候建议指定其堆内存的最大值,启动时添加JVM参数-Xmx1024m。程序运行起来之后可以利用jps或者jcmd查看运行的程序进程号。After getting the process number, use the jstat command to view GC information, such as dynamic monitoring GC statistics. Count every 1000 milliseconds, and output column headers after every 10 rows of data:
The above two steps can also be merged into a single jstat-gc-h20 $(jcmd | grep "com.example.springbootdemo.SpringBootDemoApplication" | awk'{print $1}') 1000
Of course, in addition to dynamically monitoring GC information, you can also print GC log information to a file, and then use GC analysis tools for analysis.
By adding the JVM parameter "- Xmx1024m-Xloggc:/gc.log" when the program starts, you can print the GC log to a gc.log file, and then you can use the GCViewer tool to assist in analyzing the GC log file, reference address: https://github.com/chewiebug/GCViewer
After downloading GCViewer, double-click the gcviewer-x.xx-SNAPSHOT.jar file to run, and then import the gc.log log file to observe the GC information.
Before GC tuning, we need to know the information about the current JVM parameters. The command java-XX:+PrintFlagsFinal-version prints all the JVM parameters. To view the specified parameters, you can use java-XX:+PrintFlagsFinal-version if you need to view the value of UseAdaptiveSizePolicy. | grep UseAdaptiveSizePolicy
Adjust the value of-XX:ParallelGCThreads to specify the number of concurrent threads in GC. For example, you can add "- Xmx1024m-XX:ParallelGCThreads=4" to the startup parameters of JVM, adjust the number of concurrent threads in GC, and observe the information of GC, such as the number of Full GC, the total time of FGC,Full GC, the total time of FGCT,GC, and so on.
Similarly, we can specify-XX:MaxGCPauseMills in the JVM startup parameters, use the G1 collector-XX:+UseG1GC, etc., adjust the JVM startup parameters, collect GC logs, and have more monitoring to adjust accordingly, and then find the optimal value.
After reading the above, do you have any further understanding of what the JVM parameters are and how to tune them? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.