High CPU Analysis

Source: Internet
Author: User

The CPU is too high, typically with a dead loop, or a CPU-intensive application.


Positioning problem Ideas:

1. See which process battle is too high.

2. Check to see which thread is consuming too much of the process.

3. After checking the corresponding CPU high thread, print out the outgoing stacks with jstack to see the corresponding stack information


The following is the entire instance,


First, find out which process is consuming high CPU
With command: Top


Results:
7907 Zhao 0 3279m 645m 30m S 8.2 8:34.18 java
21372 Zhao 0 4226m 384m 13m S 4.9 4:40.90 java


Can see 7907 and 21372 This process is relatively high, where 7907 is the Eclipse program, you can see all Java processes with JPS
And 21372 is our application, so the main location is 21372 this process


Two. Identify the corresponding process, the CPU is high-consuming thread
With command: top-h-P 21372
Results:
PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND
21673 Zhao 0 4226m 384m 13m R 4.9 6:06.72 java
21372 Zhao 0 4226m 384m 13m S 0 4.9 0:00.00 Java
21377 Zhao 0 4226m 384m 13m S 0 4.9 0:06.95 Java
21379 Zhao 0 4226m 384m 13m S 0 4.9 0:00.25 Java


You can see that 21673 threads are consuming 46% of the CPU.


Three. Print out a thread stack that consumes too much CPU
The second step is to find the thread ID: 21673, because jstack prints out the process line stacks 16 process encoding,
So will: 21673 turn into 16 binary for 54A9


Command: Jstack 21372 (process), if you want to save to a file: Jstack 21372 >/home/yourpath/c.log


Results:
"Http-nio-8082-exec-1" daemon prio=10 tid=0x00007f9a44003800 nid=0x54a9 runnable [0x00007f9acc1a5000]
Java.lang.Thread.State:RUNNABLE
At Java.io.FileOutputStream.writeBytes (Native Method)
At Java.io.FileOutputStream.write (fileoutputstream.java:345)
At Java.io.BufferedOutputStream.flushBuffer (bufferedoutputstream.java:82)
At Java.io.BufferedOutputStream.flush (bufferedoutputstream.java:140)
-Locked <0x0000000784c1fcd8> (a java.io.BufferedOutputStream)
At Java.io.PrintStream.write (printstream.java:482)
-Locked <0x0000000784c1fcb8> (a java.io.PrintStream)
At Sun.nio.cs.StreamEncoder.writeBytes (streamencoder.java:221)
At Sun.nio.cs.StreamEncoder.implFlushBuffer (streamencoder.java:291)
At Sun.nio.cs.StreamEncoder.flushBuffer (streamencoder.java:104)
-Locked <0x0000000784c1fe08> (a java.io.OutputStreamWriter)
At Java.io.OutputStreamWriter.flushBuffer (outputstreamwriter.java:185)
At Java.io.PrintStream.write (printstream.java:527)
-Locked <0x0000000784c1fcb8> (a java.io.PrintStream)
At Java.io.PrintStream.print (printstream.java:669)
At Java.io.PrintStream.println (printstream.java:806)
-Locked <0x0000000784c1fcb8> (a java.io.PrintStream)
At Com.test.mainsite.controller.IndexController.home (indexcontroller.java:21)
At Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)


With the converted thread number: 54A9 lookup, you can see the thread line above
Over here:
At Com.test.mainsite.controller.IndexController.home (indexcontroller.java:21)
At Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
Is that the current thread has high CPU business code






High CPU Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.