Author: Lu Hongli
The introduction
Those who have dealt with online problems will almost always encounter the problems of server CPU surge and excessive GC times. The final visual result of these problems is that the system runs slowly and has a lot of alarms. This article mainly aims at the server CPU surge problem, provides the troubleshooting idea of the problem, so as to locate the code point of the problem, and then provides the idea of solving the problem.
The problem found
In the task of calculating the combined maximum fallback algorithm, CPU will increase significantly every time it is executed.
Location problem
1. The query running process PID, command: ps – ef | grep Java
2. Run the top-hp PID command to query the running status of all threads in a process
3. Run the printf ‘%x\n’ ID command to find the ID of the thread that consumes CPU and convert the ID to hexadecimal
4. Jstack check thread information, command: jstack PID | grep [thread hexadecimal] – A 30
5. Use JProfiler to view CPU memory usage. The jStack command can basically locate specific METHODS that consume CPU memory
You can see the number of DateTime() object instances generated visually through instance changes
Problem solving
Through the above steps 4 and 5 can locate is V3PlanNavIndicatorCalcUtils calMaxDrawDownRate () method of a large number of DateTime () generates a DateTime object String dates (20210818, 20210819,… …). The data sort and comparison size optimization uses string comparison instead of DateTime comparison
Graphical comparison
1. Comparison of CPU usage
2. Load comparison of physical servers
3.G1 Young GC comparison
conclusion
The above shows a complete process of locating and solving online problems. The tool uses the Linux commands top, printf, jstack and the third-party tool JProfiler. The main cause of the problem is the memory footprint of the DateTime() object generation, which also leads to frequent garbage collection by the Young GC.
One more thing
Snowball’s engineer team is recruiting, Java engineer, operation and maintenance development engineer, test development engineer, algorithm engineer, interested students can check the original text to see the specific position and requirements, just waiting for you.