In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
If the running status of JVM is monitored by tools and Java api, this article introduces in detail the corresponding analysis and solutions to this problem, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
The setting of JVM parameters needs to be set according to the characteristics of the application. The setting of each parameter needs to be monitored for a long time and constantly adjusted to find the * setting solution. If the running status of JVM is monitored by tools and Java api, and the use of each tool is introduced in detail.
Data to be monitored: (memory usage who uses memory GC)
Memory usage-heap&PermGen
@ indicates the value that can be obtained through jmap-heap pid
# indicates the value that can be obtained through jstat-gcutil pid
Parameters can be viewed in a variety of ways only one of which is randomly listed in this article.
Describe * * value current value alarm value heap memory @ Heap Configuration::MaxHeapSize
Sum (eden+servivor+old) sum (eden+servivor+old) self-set non-heap memory sum (perm+native) No Eden@Eden Space::capacity@Eden Space::used, no Survivor0@From Space::capacity@From Space::used, no Survivor1@To Space::capacity@To Space::used, no New gen
(note that it is different from the Xmn parameter setting) @ New Generation::capacity
Eden + 1 Survivor Space@New Generation::used No Old gen@concurrent mark-sweep generation::capacity
(CMS is the gc for the old area, so it means old gen here) @ concurrent mark-sweep generation::capacity (CMS):: used self-set Perm Gen@Perm Generation::capacity@Perm Generation::used self-set
Memory usage-config
Describe the configuration value MaxTenuringThresholdjinfo-flag MaxTenuringThreshold pidMinHeapFreeRatio@Heap Configuration::MinHeapFreeRatioMaxHeapFreeRatio@Heap Configuration::MaxHeapFreeRationew gen gc@using... Statistics on the total number of classes under the in the new generationold gen gcnew gen gc statement?
Memory usage-C heap
◆ top or ps aux
Who uses memory?
◆ Heap
Jmap-histo
Jmap-dump, then mat
◆ C heap
Google perftools
The condition of GC
Describe the collection times, collection time, apply pause time Full GC#FGC#FGCT setting-View Young GC#YGC#YGCT in the log after XX:+PrintGCApplicationStoppedTime as above
-XX:+PrintGCDetails-XX:+PrintGCTimeStamps-XX:+PrintHeapAtGC-XX:+PrintGCApplicationStoppedTime-Xloggc:logs/gc.log
Introduction to common tools: jinfo jmap jstack jstat
Jinfo
◆ can obtain java configuration information from a given java process or core file or remote debug server. Including java system properties and JVM parameters (command line flags). Note that parameters that are not configured in the jvm startup parameters can also use jinfo-flag xxx pid to output default values (useful, but it seems that some abbreviated parameters cannot be found).
◆ can modify the opts of the java process at run time.
◆ is available only in JDK versions of solaris and linux.
◆ can be used using the jinfo-h query.
Jmap
Observe the physical memory footprint of the running jvm.
If you use SHELL jmap-histo pid > a.log to save it to text, after a while, using the text comparison tool, you can compare which objects have been recycled by GC.
The parameter is very simple. Check jmap-h directly.
For example:
Jmap-heap pid jmap-dump:format=b,file=heap.hprof
Dump files can be viewed by MemoryAnalyzer analysis. URL: http://www.eclipse.org/mat/, you can check the number of objects, memory usage, threads and so on.
Why does jmap-dump:live trigger Full GC?
Jstack
Observe the running status and current state of all current threads in jvm
If the java program crashes to generate a core file, the jstack tool can be used to get information about the java stack and native stack of the core file, so that you can easily know how the java program crashed and where the program went wrong. In addition, the jstack tool can be attached to a running java program to see the java stack and native stack information of the running java program at that time. If the running java program presents the state of hung, jstack is very useful. Currently, it is only available in JDK versions of Solaris and Linux.
The parameter is very simple. Check jstack-h directly.
For example:
Jstack pid
Jstat
JVM Monitoring tool (Java Virtual Machine Statistics Monitoring Tool). The built-in instructions of JVM are used to monitor the resources and performance of Java applications in real time, including various heap and non-heap sizes and their memory usage, classloader, compiler, garbage collection status and so on.
For example:
Jstat-printcompilation-h20 3024 250600
Print every 250ms for a total of 600times and display the head every 10 lines
Grammatical structure:
Usage: jstat-help |-options jstat-[- t] [- h] [[]]
Parameter description:
◆-h n outputs the title every few lines
The process number of the ◆ vmid VM, that is, the currently running java process number
◆-t displays the timestamp since JVM was started in the * * column.
◆-J modifies parameters of the java process. Similar to jinfo-flag =. For example,-J-Xms48m sets the initial heap to 48m. See here for details. This parameter is useful and can be adjusted during operation to facilitate testing and monitoring.
◆-option option is the parameter to be detected. The parameter list can be obtained through jstat-options. The meaning of each parameter and output field is described below.
Class statistics class loader behavior information compiler statistics compilation behavior information gc statistics jdk gc statistics heap information statistics heap memory different generations of heap capacity information gccause statistics gc statistics (same as-gcutil) and events that cause gc statistics gcnew statistics gc information (more detailed than gcutil) gcnewcapacity statistics gc new generation heap capacity gcold statistics gc, elderly area gcoldcapacity statistics gc, elderly area heap capacity gcpermcapacity statistics gc, permanent area heap capacity gcutil statistics gc Heap case printcompilation Statistical compilation behavior Information
-class option:Class Loader Statistics
ColumnDescriptionLoadedNumber of classes loaded.BytesNumber of Kbytes loaded.UnloadedNumber of classes unloaded.BytesNumber of Kbytes unloaded.TimeTime spent performing class load and unload operations.
-compiler:HotSpot Just-In-Time Compiler Statistics
ColumnDescriptionCompiledNumber of compilation tasks performed.FailedNumber of compilation tasks that failed.InvalidNumber of compilation tasks that were invalidated.TimeTime spent performing compilation tasks.FailedTypeCompile type of the last failed compilation.FailedMethodClass name and method for the last failed compilation.
-gc Option:Garbage-collected heap statistics
ColumnDescriptionS0CCurrent survivor space 0 capacity (KB). S1CCurrent survivor space 1 capacity (KB). S0USurvivor space 0 utilization (KB). S1USurvivor space 1 utilization (KB). ECCurrent eden space capacity (KB). EUEden space utilization (KB). OCCurrent old space capacity (KB). OUOld space utilization (KB). PCCurrent permanent space capacity (KB). PUPermanent space utilization (KB). YGCNumber of young generation GC Events.YGCTYoung generation garbage collection time.FGCNumber of full GC events.FGCTFull garbage collection time.GCTTotal garbage collection time.
-gccapacity Option:Memory Pool Generation and Space Capacities
ColumnDescriptionNGCMNMinimum new generation capacity (KB). NGCMXMaximum new generation capacity (KB). NGCCurrent new generation capacity (KB). S0CCurrent survivor space 0 capacity (KB). S1CCurrent survivor space 1 capacity (KB). ECCurrent eden space capacity (KB). OGCMNMinimum old generation capacity (KB). OGCMXMaximum old generation capacity (KB). OGCCurrent old generation capacity (KB). OCCurrent old space capacity (KB). PGCMNMinimum permanent generation capacity (KB). PGCMXMaximum Permanent generation capacity (KB). PGCCurrent Permanent generation capacity (KB). PCCurrent Permanent space capacity (KB). YGCNumber of Young generation GC Events.FGCNumber of Full GC Events.
-gccause Option:Garbage Collection Statistics, Including GC Events
ColumnDescriptionLGCCCause of last Garbage Collection.
GCCCause of current Garbage Collection.
The previous field is the same as gcutil.
-gcnew Option:New Generation Statistics
ColumnDescriptionS0CCurrent survivor space 0 capacity (KB). S1CCurrent survivor space 1 capacity (KB). S0USurvivor space 0 utilization (KB). S1USurvivor space 1 utilization (KB). TTTenuring threshold.MTTMaximum tenuring threshold.DSSDesired survivor size (KB). ECCurrent eden space capacity (KB). EUEden space utilization (KB). YGCNumber of young generation GC events.YGCTYoung generation garbage collection time.
-gcnewcapacity Option:New Generation Space Size Statistics
ColumnDescriptionNGCMN
Minimum new generation capacity (KB).
NGCMXMaximum new generation capacity (KB). NGCCurrent new generation capacity (KB). S0CMXMaximum survivor space 0 capacity (KB). S0CCurrent survivor space 0 capacity (KB). S1CMXMaximum survivor space 1 capacity (KB). S1CCurrent survivor space 1 capacity (KB). ECMXMaximum eden space capacity (KB). ECCurrent eden space capacity (KB). YGCNumber of young generation GC events.FGCNumber of Full GC Events.
-gcold Option:Old and Permanent Generation Statistics
ColumnDescriptionPCCurrent permanent space capacity (KB). PUPermanent space utilization (KB). OCCurrent old space capacity (KB). OUold space utilization (KB). YGCNumber of young generation GC events.FGCNumber of full GC events.FGCTFull garbage collection time.GCTTotal garbage collection time.
-gcoldcapacity Option:Old Generation Statistics
ColumnDescriptionOGCMNMinimum old generation capacity (KB). OGCMXMaximum old generation capacity (KB). OGCCurrent old generation capacity (KB). OCCurrent old space capacity (KB). YGCNumber of young generation GC events.FGCNumber of full GC events.FGCTFull garbage collection time.GCTTotal garbage collection time.
-gcpermcapacity Option: Permanent Generation Statistics
ColumnDescriptionPGCMNMinimum permanent generation capacity (KB). PGCMXMaximum permanent generation capacity (KB). PGCCurrent permanent generation capacity (KB). PCCurrent permanent space capacity (KB). YGCNumber of young generation GC events.FGCNumber of full GC events.FGCTFull garbage collection time.GCTTotal garbage collection time.
-gcutil Option:Summary of Garbage Collection Statistics
ColumnDescriptionS0Survivor space 0 utilization as a percentage of the space's current capacity.S1Survivor space 1 utilization as a percentage of the space's current capacity.EEden space utilization as a percentage of the space's current capacity.OOld space utilization as a percentage of the space's current capacity.PPermanent space utilization as a percentage of the space's current capacity.YGCNumber of young generation GC events.YGCTYoung generation garbage collection time.FGCNumber of full GC events.FGCTFull garbage collection time.GCTTotal garbage collection time.
-printcompilation Option: HotSpot Compiler Method Statistics
ColumnDescriptionCompiledNumber of compilation tasks performed.SizeNumber of bytes of bytecode for the method.TypeCompilation type.MethodClass name and method name identifying the compiled method. Class name uses "/" instead of "." As namespace separator. Method name is the method within the given class. The format for these two fields is consistent with the HotSpot-XX:+PrintComplation option.
Java api mode monitoring
Some api are provided in jre to view the internal information of the running jvm, these api are included in the java.lang.management package, and the interfaces in this package are introduced in jdk 5, so this information can only be accessed in this way in jdk 5 and above. Here is a brief description of what information this includes and how to access it.
Through this api, you can access information about class loading of the running jvm, information about the jit compiler, memory allocation, information about threads, and information about the operating system running jvm. Nine interfaces are provided in the java.lang.management package to access this information. Using the static get method of ManagementFactory, you can get instances of the corresponding interfaces, through which you can get the relevant information you need.
For a more detailed introduction to MBean, see what's New in Java SE 6: JMX and system Management
Demo1: see how many classes are loaded in the currently running jvm. To learn more about how to use these api, you can refer to the detailed api documentation in the java.lang.management package.
Public class ClassLoaderChecker {public static void main (String [] args) throws Exception {ClassLoadingMXBean bean = ManagementFactory.getClassLoadingMXBean (); System.out.println (bean.getLoadedClassCount ());}}
Demo2: custom Mbean Type. The recorded data can be viewed through tools such as jconsole or self-written code.
/ / tool method public static ObjectName register (String name, Object mbean) {try {ObjectName objectName = new ObjectName (name); MBeanServer mbeanServer = ManagementFactory .getPlatformMBeanServer (); try {mbeanServer.registerMBean (mbean, objectName);} catch (InstanceAlreadyExistsException ex) {mbeanServer.unregisterMBean (objectName) MbeanServer.registerMBean (mbean, objectName);} return objectName;} catch (JMException e) {throw new IllegalArgumentException (name, e);}} / / step 1: define Mbean interface: / / casually define public interface DemoMBean {public AtomicLong getInvokeCount () Step 2: implement the interface and register: public class DemoImpl implements DemoMBean {public final static String DEFAULT_OBJECT_NAME_PREFIX = "com.redcreen.demo:type=demo"; register ("com.redcreen.demo:type=demo", DemoImpl.instance) } / / you can view the data in jconsole. The answers to questions about monitoring the running status of JVM through tools and Java api are shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.