SuperAPI AI Directory

arthas-cpu-high

Coding & development

View repository

Updated 10-15 16:47

About this skill

JVM High CPU Troubleshooting Guide (Arthas)

Applicable scenarios: machine CPU spikes, application response slowdown, abnormally elevated load.

Principle: First use low-risk tools to identify "which thread is busy," then gradually narrow down to "which method/code path."

1) First confirm the current overall JVM state (low risk)

  • Use dashboard to view CPU/thread/GC overview (recommended to set a limited number of iterations):
    • Pay attention to: whether CPU, thread count, and GC count/duration are abnormal.

2) Locate the busiest threads (key step)

  • Use thread to find the top N busiest threads and print their stacks:
    • For example:topN=3 or topN=5
  • Record each hot thread's threadId and key stack method names (you can use take_notes to record evidence).

Determine the direction:

  • If the stack shows it is in java.util.regex, JSON serialization, log formatting, etc.: it may be CPU-intensive computation.
  • If the stack shows lock contention: continue checking whether there is a large amount of BLOCKED, and consider using thread(blocking=true) to find the source thread of the blocking.

3) Further confirm the call path of the hot method (on demand, with limits)

When the hot thread stack points to a "suspicious method":

  • Prefer using stack / trace to confirm the path for that method (avoid broad matching).
  • If you need to observe input parameters/return values, then consider watch or tt, and set reasonable execution counts and timeouts to avoid putting pressure on production.

4) Output diagnostic conclusions

The report should include at least:

  • Symptoms and evidence: dashboard summary + key fragments of topN thread stacks
  • Preliminary conclusion: what type of logic CPU is mainly consumed by (computation/locks/GC/logging, etc.)
  • Next steps: the target methods recommended for further trace/watch (give the precise scope of class name + method name), or recommend that the user provide the main package name/key interface information to continue narrowing down