In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "what are the JVM tuning tools", which is easy to understand and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn what JVM tuning tools have.
JVM tuning tool
Jconsole,jProfile,VisualVM
Jconsole:jdk comes with simple function, but it can be used when the system has a certain load. There is a very detailed tracking of garbage collection algorithms. For more information, please see here.
JProfiler: commercial software, you need to pay for it. Powerful. For more information, please see here.
VisualVM:JDK comes with powerful functions, similar to JProfiler. Recommend.
How to optimize
Observe memory release, collection class check, object tree
The above tuning tools provide powerful features, but in general, they are generally divided into the following categories
Heap information view
Can view heap space allocation (younger generation, older generation, persistent generation allocation) to provide real-time garbage collection function garbage monitoring (long-term monitoring of recycling)
View in-heap classes, object information: quantity, type, etc.
View object references
With the ability to view heap information, we can generally solve the following problems smoothly:
-- whether the size division of the older generation and the younger generation is reasonable
-- memory leak
-whether the setting of garbage collection algorithm is reasonable
Thread monitoring
Thread information monitoring: system thread number thread status monitoring: what state each thread is in
Dump thread details: view the internal operation of the thread deadlock check
Hot spot analysis
CPU hotspots: check which methods of the system take up a lot of CPU time
Memory hotspot: check the number of objects in the system * (the surviving objects are counted together with the destroyed objects within a certain period of time)
These two things are very helpful for system optimization. We can find the bottleneck of the system and optimize the system according to the hot spots found, instead of optimizing all the code aimlessly.
Snapshot
A snapshot is a freeze when the system runs to a certain time. When we are tuning, it is impossible to track all the system changes with our eyes. Depending on the snapshot function, we can make different objects (or classes, threads, etc.) at two different running times of the system in order to find the problem quickly.
For example, I want to check whether any objects that should be collected have been left out after garbage collection in the system. Then, I can take a snapshot of the heap before and after garbage collection, and then compare the objects of the two snapshots.
Memory leak check
Memory leakage is a relatively common problem, and the solution is also more general, here we can focus on it, while the thread, hot issues are specific analysis of specific problems.
Memory leakage can generally be understood as the misuse of system resources (resources, heaps, stacks, threads, etc.), resulting in the use of resources can not be recycled (or not recycled), resulting in new resource allocation requests can not be completed, resulting in a system error.
Memory leaks do great harm to the system because it can directly cause the system to crash.
It needs to be distinguished that there is a difference between memory leaks and system overload, although the end result may be the same. A memory leak is an error caused by the non-recovery of used resources, while the system is overloaded because the system really does not have that many resources to allocate (other resources are in use).
The old generation reactor space is full.
Exception: java.lang.OutOfMemoryError: Java heap space
Description:
This is the most typical way of memory leakage, which simply means that all heap space is filled with garbage objects that cannot be recycled, and the virtual machine can no longer allocate new space.
As shown in the figure above, this is a very typical garbage collection diagram of memory leaks. All the peak parts are a garbage collection point, and all the trough parts represent the remaining memory after a garbage collection. Connecting all the trough points, you can find a line from bottom to high, which shows that over time, the heap space of the system is constantly occupied, and eventually the whole heap space will be filled. Therefore, it can be preliminarily considered that there may be a memory leak within the system. (the above figure is for example only. In practice, it takes longer to collect data, such as a few hours or days.)
Resolve:
This way is also relatively easy to solve, generally according to the comparison before and after garbage collection, at the same time according to the object reference (common collection object reference) analysis, basically can find the leak point.
The enduring generation is occupied.
Exception: java.lang.OutOfMemoryError: PermGen space
Description:
The Perm space is full. An exception that is thrown when storage space cannot be allocated for a new class. This exception did not exist before, but it is more common today when Java reflection is heavily used. The main reason is that a large number of classes generated by dynamic reflection are constantly loaded, resulting in a full Perm area.
What's even more frightening is that even if different classLoader uses the same class, it will be loaded, which is equivalent to the same thing. If there are N classLoader, then it will be loaded N times. Therefore, in some cases, this problem is basically regarded as unsolved. Of course, there are not many cases where there are a lot of classLoader and a lot of reflection classes.
Resolve:
1.-XX:MaxPermSize=16m
two。 Switch to JDK. Like JRocket.
Stack overflow
Exception: java.lang.StackOverflowError
Description: there is no need to say much about this, generally, it is not returned recursively, or caused by a circular call.
Thread stack is full
Exception: Fatal: Stack size too small
Description: there is a limit to the space size of a thread in java. After JDK5.0, the value is 1m. The data associated with this thread will be stored in it. But when the thread space is full, the above exception will occur.
Solution: increase the thread stack size. -Xss2m. However, this configuration does not solve the fundamental problem, and it depends on whether there is a leak in the part of the code.
The system memory is full
Exception: java.lang.OutOfMemoryError: unable to create new native thread
Description:
This exception is caused by the operating system not having enough resources to generate this thread. When the system creates a thread, in addition to allocating memory in the Java heap, the operating system itself needs to allocate resources to create the thread. Therefore, when the number of threads is large to a certain extent, there may be space in the heap, but the operating system cannot allocate resources, so this exception occurs.
The more memory allocated to the Java virtual machine, the less remaining resources of the system. Therefore, when the system memory is fixed, the more memory allocated to the Java virtual machine, the less threads the system can generate, which is inversely proportional to the two. At the same time, you can modify-Xss to reduce the space allocated to a single thread, or you can increase the total number of threads produced in the system.
Resolve:
1. Redesign the system to reduce the number of threads.
two。 If the number of threads cannot be reduced, reduce the size of a single thread through-Xss. So that more threads can be produced.
These are all the contents of the article "what are the JVM tuning tools?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.