In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces you to JVM memory tuning skills, content is very detailed, interested friends can refer to reference, hope to help you.
Here to describe the JVM memory setting principle and tuning, the default java virtual machine size is relatively small, java will report error when processing large data: java.lang.OutOfMemoryError.
How JVM memory is set
The default java virtual machine size is relatively small, java will report error when processing large data: java.lang.OutOfMemoryError. To set jvm memory, for a separate.class, you can set jvm memory at Test runtime as follows:
java -Xms64m -Xmx256m Test
-Xms is to set the size of memory initialization
-Xmx is the setting *** the size of memory that can be used (*** do not exceed the physical memory size)
In weblogic, the size of virtual memory for each domain can be set in startweblogic.cmd, and the default setting is in commEnv.cmd.
Tuning JVM memory
Java Heap is divided into 3 zones: Young, Old and Permanent. Young saves the object just instantiated. When the area is full, GC moves objects to the Old area. The Permanent zone is responsible for preserving reflective objects and is not discussed in this article. Heap allocation for JVM can be set using the-X parameter,
-Xms Initial Heap Size
-Xmx javaheap*** value
- heap size of Xmn younggeneration
JVM has 2 GC threads. *** Three threads are responsible for reclaiming Heap's Young section. The second thread traverses the Heap when the Heap is insufficient, upgrading the Young area to the Older area. The size of the Older section is equal to-Xmx minus-Xmn, and the value of-Xms cannot be set too large because forcing a second thread to run will degrade JVM performance.
Why does GC occur frequently in some programs?
The reasons are as follows:
System.gc() or Runtime.gc() was called within the program.
Some middleware software calls its own GC methods, and parameters need to be set to disable these GC methods.
Java's Heap is too small, and the default Heap value is generally small.
Frequently instantiated objects, Release objects. Try to save and reuse objects at this point, for example using StringBuffer() and String().
If you find that after each GC, the Heap's remaining space is 50% of the total space, this means that your Heap is in a healthy state. Many server-side Java programs have 65% free space after each GC. Experience:
Server-side JVM*** Set-Xms and-Xmx to the same value. To optimize GC, *** let the value of-Xmn be approximately 1/3 of-Xmx [2].
2. A GUI program *** runs GC every 10 to 20 seconds, each time within half a second [2].
Note:
1. Increasing the size of the Heap reduces the frequency of GC, but it also increases the time per GC. And while GC is running, all user threads are suspended, meaning Java applications do nothing during GC.
Heap size does not determine the memory usage of a process. The memory usage of the process is larger than the value defined by-Xmx because Java allocates memory for other tasks, such as Stack per thread.
2. Stack settings
Each thread has its own Stack.
-Xss Stack size per thread
Stack size limits the number of threads. If Stack is too large, it will cause memory overflow. - The Xss parameter determines the Stack size, for example-Xss 1024K. If Stack is too small, it will also cause Stack overflow.
3. hardware environment
The hardware environment also affects GC efficiency, such as the type of machine, memory, swap space, and number of CPUs.
If your program needs to create a lot of transient objects frequently, it will cause the JVM to GC frequently. In this case, you can increase the memory of the machine to reduce the use of Swap space [2].
4.4 species GC
*** Single thread GC, default GC., This GC is suitable for single-CPU machines.
The second type is ThroughputGC, which is a multithreaded GC for multi-CPU, high-thread programs. The second GC is similar to the *** GC except that GC is multithreaded in the Young section, but single-threaded in the Old section as in the *** section. - XX:+UseParallelGC parameter starts the GC.
The third type is ConcurrentLowPauseGC, similar to *** type, suitable for multiple CPUs, and requires a reduction in program stall time caused by GC. This GC can run applications at the same time as recycling in the Old Zone. - XX:+ UseConcepMarkSweepGC parameter starts the GC.
The fourth type is IncrementalLowPauseGC, which is suitable for reducing the time of program stagnation caused by GC. This GC can recycle a portion of Old objects while Young is recycling them. - The Xincgc parameter starts the GC.
What skills about JVM memory tuning are shared here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
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.