我要评分
获取效率
正确性
完整性
易理解

Tuning Process

Prerequisites

  • The server and OS are running properly.
  • An SSH remote login tool has been installed on the local PC.
  • The Java program to be tuned is running on the target server.

Procedure

Obtain the required demo from testdemo.

  1. Perform real-time profiling.

    On the Overview tab page, it is found that the CPU load of the program remains high.

    Figure 1 Real-time profiling - Overview

    Check what the program is doing or whether a hotspot function is being executed.

  2. Perform sampling profiling.

    The sampling duration can be set to a larger value.

    Figure 2 Creating a sampling profiling task
  3. View the sampling profiling result.
    Figure 3 Sampling profiling - Overview

    On the Overview tab page, the CPU usage in user mode is high, indicating that the CPU mainly executes Java code.

    If the kernel-mode CPU usage is high, the CPU performs more system-related operations.

  4. View the Method Sampling results on the CPU tab page.

    According to the flame graph of the Java method sampling, the method sampling of the program mainly falls in two function calls during the sampling period, which reflects that the CPU consumes more time in those two functions.

    Figure 4 Sampling profiling - Flame graph

    According to the fully qualified names of the functions displayed in the details, we can find that the two functions are user-developed.

    Figure 5 Sampling profiling - Inverted flame graph

    Select Call tree by thread in Graph Type. The sampling focuses on two functions, which is the same as suggested by the flame graph.

    Figure 6 Sampling profiling - CPU (Call tree by thread)
  5. Analyze the causes.

    Based on the fully qualified class name of the hotspot functions suggested by the flame graph and call tree, search for the corresponding functions in the code to analyze the service logics.

    The flame graph of a user program is complex. You need to hunt out the target functions step by step.

Summary

Hotspot functions in Java are located using the flame graph. Then, service code is searched based on the fully qualified names of the methods provided by the flame graph to tune the code.

When tuning other programs, you need to perform tuning operations based on the analysis results collected by the Java Profiler and the corresponding tuning suggestions. For details about the tuning roadmap, see this practice.