Troubleshooting

更新时间:
复制 MD 格式

Note:

Run diagnostic operations sequentially. If you start a new operation before the current one is complete, the new operation fails. An operation is complete when the Dump button on the Files page is enabled. A diagnostic report takes a few seconds to generate. A heap snapshot can take from several seconds to several minutes to generate, depending on the heap size. Other operations run for 3 minutes.

Scrape performance data

Go to the application console. Click the Instance button for the target application. On the instance page, locate the Scrape Performance Data feature of the Node.js Performance Platform, as shown in the following figure:

performance

To diagnose a memory leak, scrape a heap snapshot. To diagnose high CPU usage, scrape CPU Profile data. The following examples show how to use the troubleshooting features in the Node.js Performance Platform to diagnose high CPU usage and a memory leak.

High CPU usage

If CPU usage is high, click the CPU Profile button. This action generates a CPU Profile log file that covers a 3-minute period. In the left-side navigation bar, click Files to view the generated CPU Profile file. The following figure shows the file after it is dumped to the cloud:

cpu

The Node.js Performance Platform provides two tools to analyze CPU profiles. The following sections describe each tool.

Flame graph

Click the first Analyze button in the preceding figure to open the flame graph analysis view, as shown in the following figure:

flame

The slow function in test.js is the user-written function that consumed the most time during profiling, accounting for 75.5% of the total duration. The next step is to optimize the slow function.

DevTools

Click the second Analyze button in the preceding figure to open the DevTools analysis view, as shown in the following figure:

dev

Similarly, the slow function took the longest to execute and requires optimization.

Memory leak

If a memory leak occurs, click the Heap Snapshot button, as shown in the first figure of this topic. This action dumps the heap structure of the current process into a file. In the left-side navigation bar, click Files to view the generated heap snapshot file. The following figure shows the file after it has been dumped to the cloud:

mem

Two analysis methods are also available. The following sections describe each method.

MAT analysis

Click the first Analyze button in the preceding figure to open the MAT analysis view, as shown in the following figure:

mem-m

The view shows that the source of the leak is an array in the test-alinode.js file.

DevTools analysis

The DevTools analysis feature provides an experience identical to that of the native DevTools in Chrome, as shown in the following figure:

mem-d

More examples

For more diagnostic examples from actual projects, see the Best practices section.