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 主机名: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, thread, class, VM summary and MBeans .

现在我也找了很多测试的朋友,做了一个分享技术的交流群,共享了很多我们收集的技术文档和视频教程。
如果你不想再体验自学时找不到资源,没人解答问题,坚持几天便放弃的感受
可以加入我们一起交流。而且还有很多在自动化,性能,安全,测试开发等等方面有一定建树的技术大牛
分享他们的经验,还会分享很多直播讲座和技术沙龙
可以免费学习!划重点!开源的!!!
qq群号: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 in Figure 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 are created when the Java virtual machine starts.

● 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 monitored heap and non-heap memory provided 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: in the Perm Gen memory pool Read-write area;

Perm Gen [shared-ro] memory pool: 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 These class data areas will be shared during runtime, and the shared areas have 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. If 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 some 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: the young generation (sometimes called the "nursery") and the old generation . The young generation includes one "Eden space" and two "survivor spaces". Initially, the VM places all objects in "Eden space" memory pool, and most objects "die" there. When it performs a minor GC (minor GC), the VM transfers the remaining objects from "Eden space" to "survivor spaces", and virtual long-term survival Time objects are moved to the "tenured" space of the old generation. When the old generation is filled, there will be a complete GC. A complete GC will tend to be very slow because it involves all living objects. The permanent generation contains virtual Reflection of all the 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 beginning;
processing CPU time: the beginning of the Java VM, the total amount of CPU time consumed;
total compilation time: the cumulative time spent in JIT compilation time spent;

Thread and class information mainly includes the following information:

Active threads: currently active threads;
Peak: the maximum number of threads;
Daemon threads: threads running in the background;
Total number of started threads: the number of threads started so far;
Current class loaded: the currently running process The total number of loaded classes;
the total number of loaded classes: the total number of loaded classes so far; the
total number of unloaded classes: the total number of unloaded classes so far;

Memory information mainly includes the following information:

Current heap size: the memory space allocated by the current heap;
allocated memory: the currently allocated memory size;
the maximum value of the heap size: the maximum value of the heap allocated memory;
pending end operation: the object that is currently temporarily suspended;
garbage collection Collector: The garbage collector describes the name of the collector, the amount of memory collected by the collector and the time spent collecting these memories;

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;
Class path: The class path used by the system class loader to search for class files;
Library path: To search when loading the library Path list;
Boot class path: 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 properties

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 (that is, the bold text 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. Figure 10-16 shows 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, and 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

Finally, I would like to thank everyone who has read my article carefully. Looking at the increase in fans and attention, there is always some courtesy. Although it is not a very valuable thing, if you can use it, you can take it directly!

Software Testing Interview Document

We must study to find a high-paying job. The following interview questions are from the latest interview materials from first-tier Internet companies such as Alibaba, Tencent, Byte, etc., and some Byte bosses have given authoritative answers. After finishing this set I believe everyone can find a satisfactory job based on the interview information.
 

Insert image description here

Guess you like

Origin blog.csdn.net/m0_58026506/article/details/133102506