Performance testing – Tomcat monitoring and tuning: Jconsole monitoring

JConsole’s graphical user interface is a monitoring tool that complies with the Java Management Extensions (JMX) specification. JConsole uses the Java Virtual Machine (Java VM) to provide performance and resource consumption information for applications running on the Java platform. In Java Platform, Standard Edition (Java SE Platform) 6, JConsole has been updated to the current look and feel, similar to the Windows and GNOME desktops (other platforms will now have the standard Java graphics look and feel), as presented in this document The screenshot is from an example of the interface running on Windows XP.

Jconsole is an executable file. There is a bin file in the Java root directory. The jconsole file can be found under this file. Click to run the program directly. If the path of the jconsole is set as an environment variable, you can directly open it in the start menu. Directly enter the jconsole command in the run command to run the jconsole program. If it is not set as an environment variable, you need to write the full path.

There are two ways to start the JConsole program: One is to start with parameters; the other is to start without parameters.

When starting JConsole with parameters, there are two situations: One is to monitor local progress; the other is remote monitoring;

The command format for local monitoring is as follows:

JConsole processID

processID refers to the process ID (PID) of the application. The PID of an application can be determined using the following methods:

● On UNIX or Linux systems, you can use the ps command to find the PID of the running Java instance;

● On Windows systems, you can use Task Manager to find the PID of the java or javaw process;

For example: If you monitor the JConsole program and the process number of JConsole is 5604, you can use the following command to start JConsole:

JConsole 5604

The command format for remote monitoring is as follows:

JConsole host name: portNum

The host name is the host that needs to be monitored, and portNum is the port number of the JMX agent specified when starting the Java virtual machine.

Note: Using JConsole to monitor local applications is very useful when developing and creating prototypes, but it is not recommended for production environments because Jconsole itself also consumes a lot of system resources.

When executing the Jconsole program, without any parameter command, the Jconsole New Link dialog box will pop up, as shown in Figure 10-6.

Figure 10-6 Jconsole new connection

Jconsole has two monitoring methods: local process monitoring and remote monitoring.

●Select local process monitoring. The processes of the same user as the JConsole program will be listed in the list box below. Select one of the processes and click the connect button to enter the main interface for monitoring.

●Select remote monitoring, the required content includes. The hostname and port number of the JMX agent, as well as the username and password to access the server.

When the connection is successful, the monitoring interface will pop up, as shown in Figure 10-7.

Figure 10-7 Monitoring main interface

The monitoring content mainly includes six aspects: Overview, memory, threads, classes, VM summary and MBean.

Now I have also found a lot of test friends and created a communication group to share technology, sharing a lot of technical documents and video tutorials we collected.
If you don’t want to experience the feeling of not being able to find resources when studying on your own, having no one to answer your questions, and persisting for a few days before giving up.
You can join us to communicate. And there are many technical experts who have made certain achievements in automation, performance, security, test development, etc.
Share their experience, and also share many live lectures and technical salons
You can learn for free! Focus on it! Open source! ! !
QQ group number: 110685036

Summary information

The summary information monitoring interface mainly includes heap memory usage, number of threads, loaded classes in Java VM and CPU usage. Select each view to switch the monitored time segment, and also save the data in the view in a comma-separated (CSV) file.

Memory information

Memory monitoring information mainly provides memory consumption and memory pool information, as shown inFigure 10-8.

Figure 10-8 Memory monitoring information

Memory monitoring information mainly monitors two types of memory consumption information: Heap and non-heap memory. These two types of memory are also two types of memory managed by the Java virtual machine. Both of them are used when the Java virtual machine starts. Created.

● Heap memory is the runtime data area. All class instances and arrays of the Java VM allocate memory. It may be a fixed or variable size heap.

● Non-heap memory includes shared methods required for processing or optimization within all threads and Java virtual machines. It stores the class structure, running constant pool, field and method data, and the code of methods and constructors. The method area is logically part of the heap, depending on the specific implementation. Depending on the implementation, the Java virtual machine may not perform garbage collection or compression. Like heap memory, the method area may be a fixed or variable size, and the memory in the method area does not need to be contiguous.

In addition to the method area, the Java virtual machine may need to perform internal processing or optimization, which is also non-heap memory. For example, just-in-time (JIT) compilers require memory for storing machine code translated from the Java virtual machine’s high-performance code.

The heap and non-heap memory monitored by Jconsole mainly include the following categories:

Eden Space memory pool: The memory pool allocated when most objects are initialized;

Survivor Space memory pool: The objects contained in this memory pool are the objects that survived after recycling the Eden Space memory pool;

Tenured Gen memory pool: The objects contained in this memory pool are objects that have existed in the Survivor Space memory pool for a period of time;

Code Cache memory pool: includes the code cache of HotSpot Java VM and the memory consumed by compiling and storing code;

Perm Gen[shared-rw] memory pool: the area for reading and writing in the Perm Gen memory pool;

Perm Gen[shared-ro] memory pool: a read-only area in the Perm Gen memory pool;

Perm Gen memory pool: This memory pool includes data reflected by the virtual machine itself, such as classes and methods. The Java virtual machine will share these class data areas when it is running. The shared area has two modes: read-only and read-write.

In the chart drop-down list box, you can select different memory pools for monitoring and obtain the memory information consumed by the current memory pool. In addition, the heap and non-heap icons are displayed in the lower right corner. When you switch the displayed chart, the content displayed in the memory pool chart will also change. If it is displayed in red, it means that the memory used exceeds the memory threshold.

The memory pool and memory manager are key links in the memory system of the Java virtual machine.

A memory pool represents the memory area managed by the Java virtual machine. The Java virtual machine has at least one memory pool. It may create or delete memory pools during execution. A memory pool can belong to heap or non-heap memory.

A memory manager manages one or more memory pools. The garbage collector is a memory manager responsible for reclaiming the memory used by unreachable objects. The Java virtual machine may have one or more memory managers. During execution, it Memory managers can be added or removed, and a memory pool can be managed by more than one memory manager.

The details of memory usage are displayed in the “Details” box, mainly including the following information:

●Used: The amount of memory currently used, including memory that has been used, available or unavailable;

●Allocation: The allocated memory must ensure the usage required by the Java virtual machine. The committed memory may change over time. The Java virtual machine may release system memory, and the allocated memory may be less than what was allocated when initially started. The amount of memory allocated is greater than or equal to the amount of memory required.

●Maximum value: The maximum memory available in memory management. This value is changing or uncertain. If the memory used by the Java virtual machine continues to grow and is greater than the amount of allocated memory, then allocating memory will fail.

●GC time: cumulative garbage collection time and total call time. It may contain multiple lines, where each line represents the time consumed by a garbage collector algorithm in the Java virtual machine.

Garbage Collection (GC Garbage Collect) is a mechanism by which the Java virtual machine releases memory occupied by objects that are no longer referenced. It usually considers objects to be “alive” that are currently active and “dead” that cannot be referenced or not acquired. For objects, garbage collection is the process of releasing the memory occupied by “dead” objects. The algorithms and parameters of garbage collection have a great impact on performance.

The garbage collector of the Java HotSpot virtual machine uses generation GC. Most of the advantages of generation GC are in line with the following summary:

They create short-lived objects such as iterators and local variables;

They create some long-lived objects, such as high-level persistent objects;

Generational GC is divided into several generations, and one or more memory pools are assigned to each generation. When a generation uses the allocated memory, a local GC (also called minor collection) is executed on the virtual machine, and the memory pool reclaims the memory used by dead objects. , this partial GC is usually much faster than a full GC.

The Java HotSpot virtual machine defines two generations: Young generation (sometimes also called “nursery”) and old generation. The young generation includes one “Eden space” and two “survivor spaces”. Initially , VM puts all objects in the “Eden space” memory pool, and most objects “die” there. When it performs a minor GC, the VM transfers the remaining objects from “Eden space” to “Eden space”. “Survivor spaces”, virtual long-lived objects are moved to the “tenured” space of the old generation. When the old generation is filled, it will be a complete GC. A complete GC is often very slow because it involves all survivors. The permanent generation of objects contains reflections of all the virtual machine’s own data, such as classes and methods.

If the garbage collector is bottlenecked, performance can be improved by customizing the generation size.

Thread information

The monitoring information of the thread is shown in Figure 10-9.

Figure 10-9 Thread monitoring information

All active threads are displayed in the “Threads” list in the lower left corner. If you need to find a specified thread, you can enter the thread to be found in the “Filter” field, select a thread, and the current thread will be displayed in the text box on the right. name, status, and stack trace information.

The thread number view above dynamically displays the current number of active threads, which mainly includes two parts:The current number of active threads and the peak number of threads.

The thread monitoring view also provides a function to detect deadlock threads. Click the [Deadlock Detected] button. If there is a deadlock in any thread object monitor, the ID number of the deadlocked thread will be displayed, and Information about the current thread will be displayed.

All properties and operations of Java virtual machine thread information can be monitored in the MBean tab.

Class information

The monitoring information of the class is shown in Figure 10-10.

Figure 10-10 Type monitoring information

The number of loaded classes view shows the total number of loaded classes and the currently loaded classes. In fact, the red line indicates the total number of loaded classes and the blue line represents the currently loaded class. The details show the currently loaded classes, the total number of loaded classes, and the total number of unloaded classes.

VM summary information

The monitoring information of VM summary is shown in Figure 10-11.

Figure 10-11 VM summary information

The VM summary information mainly includes five aspects of information: Summary information, thread and class information, memory information, operating system information and other information.

The information in the summary section mainly includes the following information:

Connection name: process PID information when connecting to monitoring;

Running time: The total time the Java virtual machine has been running since the start;

Processing CPU time: The start of the Java VM, the total amount of CPU time consumed;

Total compilation time: the cumulative time spent on JIT compilation;

Thread and class information mainly includes the following information:

Active thread: currently active thread;

Peak: maximum number of threads;

Daemon thread: a thread running in the background;

Total number of threads started: the number of threads started so far;

Current classes loaded: The total number of classes loaded during the current running process;

Total number of loaded classes: The total number of classes loaded so far in the run;

Total number of unloaded classes: The total number of unloaded classes so far in the run;

Memory information mainly includes the following information:

Current heap size: the memory space allocated by the current heap;

Allocated memory: the current allocated memory size;

Maximum heap size: the maximum size of heap allocated memory;

Suspension end operation: the object that is currently temporarily suspended;

Garbage collector: The garbage collector describes the name of the collector, the amount of memory collected by the collector and the time spent collecting this memory;

Operating system information mainly includes operating system name, architecture, allocated virtual memory, total physical memory, available physical memory, total swap space and available swap space.

Other information mainly includes the following information:

VM parameters: Displays the parameters passed to the Java virtual machine through the application. These parameters do not include the parameters of the main method;

Classpath: The classpath used by the system class loader to search for class files;

Library path: A list of paths to search when loading the library;

Boot class path: A list of paths where the boot class loader searches for class files;

MBean information

The MBeans tab displays the classes of MBeans registered by the MBean server. The MBeans tab allows access to the platform MXBean server. In addition, it can also monitor and manage the MBeans of the application. The MBeans information is shown in Figure 10-12.

Figure 10-12 MBean information

The left side displays all currently running MBeans. When an MBean is selected in the MBean tree, the right side displays the MBeanInfo and descriptor information of the currently selected MBean. The relevant attributes, operations, and notification information of the current MBean are displayed below.

MBean attributes

Select an MBean in the MBean tree and click the “Attributes” node. All attributes of the MBean will be displayed. Take Memory as an example, as shown in Figure 10-13.

Figure 10-13 Memory attribute

Select a single attribute under Attributes, and the detailed information of the current attribute will be displayed on the right, as shown in Figure 10-14.

Figure 10-14 Property details

Click the attribute value (the bold font on the right) to expand the detailed attribute value information. The expanded value of the HeapMemoryUsage attribute is shown in Figure 10-15.

Figure 10-15 HeapMemoryUsage details

Double-click the attribute value to modify the displayed values. Some attributes are displayed in a chart. As shown in Figure 10-16 is the CurrentThreadUserTime attribute value in Threading.

Figure 10-16 Chart display of attribute values

MBean operations

Select an MBean in the MBean tree and click the “Operation” node. All related operations of the MBean will be displayed. Take Threading as an example, as shown in Figure 10-17.

Figure 10-17 Threading operation

Click the button in the operation call to call these methods. Click a method to display the details of the current method, as shown in Figure 10-18.

Figure 10-18 Method details

MBean Notification

Select an MBean in the MBean tree, click the “Notification” node, select a notification, and the detailed information of the notification will be displayed on the right, taking Memory as an example, as shown in Figure 10-19.

Figure 10-19 Notification details

I hope the above content is helpful to you. Friends who have been helped are welcome to like and comment!