yum install sysstat
@@ First, it is necessary to have certain principle knowledge as the basis, and second, it is necessary to master the process and method of troubleshooting and solving problems. This article will introduce the use of performance monitoring tools to help developers find the root cause of problems faster and more accurately. This article is divided into three parts, the first part will introduce the common monitoring tools in the Linux environment, the second part introduces the monitoring tools in the Windows environment, the third part will introduce the use of these monitoring tools to find out the java application step by step through a case study. The problem. The
Linux environment monitoring tool
needs to be declared first. Some of the tools described below can be used in both the Linux environment and the Windows environment, but it is more appropriate to use any tools in different environments.
Below we imagine such a scenario: one day the operation and maintenance personnel saw that the server load in the production environment increased, the CPU soared, and the memory usage increased. What should he do next? Some people may say that it will find that the load is rising and the CPU is soaring. . The reason, if it is caused by the application, kill it. If this method is used, the problem may be solved in a short time, but the problem is that the application is not available for a while, and we have not found the root cause of the problem. After the next restart, the problem will still occur. So what if a similar problem arises and the strict troubleshooting process? Before answering this question, let's take a look at several monitoring tools commonly used on Linux:
Double-click on the left side of the java program you need to monitor to monitor it. This tool includes monitoring CPU, memory, threads, and classes. It is very powerful. All the functions described above have been used on this tool. With. Of course, how to use it and how to analyze it takes time to accumulate a little.
MemoryAnalyzer.exe: As we mentioned above, it is often used to analyze memory heap usage and is a very powerful tool. Detailed use, no more details here, you can download and try it out.
The above describes the monitoring tools based on Linux and Windows environment. With these tools, we will use them to do the corresponding things. Here is a simple case to explain how to use them.
First of all, through the above introduction, we should have an impression on the troubleshooting process. Here we will sort it out:
After a java application is started, use personnel The application is found to be unavailable. For the phenomenon, we do the following analysis:
1, first check the application status on the server. Use the jps command to query the currently running java process:
The java application with the process ID of 6400 is just enabled, indicating that the application is not hanged and still running.
2, query the CPU, memory and current load situation occupied by the process ID, top -p 6400.
From the above results, the application did not cause the system load to be too high, and there was no abnormality in the CPU and memory.
3, through the above results, we speculate that the fault caused by memory can be less performance, so we prioritize the thread stack and use the jstack command to export the thread stack.
jstack 6400 > stack.out
We will transfer the file for easy viewing. 查看线程栈可以看出，主线程处于运行状态，而子线程ThreadA、ThreadB、ThreadC、ThreadD一边在等待一个锁，同时又持有另外一个锁，其实看到这里我们基本推断该应用程序存在死锁，因此造成线程等待，应用不可用。通过以上栈的信息，我们就可以到程序代码中详细查看代码了，并且修改bug解决此问题。
死锁 principle added:
As shown in the figure, the cause of the deadlock is that there is a mutual constraint between the threads, and no thread can continue to execute.
This article introduces the commonly used monitoring tools in Linux and Windows environments. Finally, a case is used to explain the troubleshooting process and how to use the monitoring tools to find out the cause of the application failure.