Download PDF
Download page Event Loop Blocking in Node.js.
Event Loop Blocking in Node.js
You can use process snapshots to examine Node.js event loop activity and identify functions with high CPU times that are blocking the event loop.
Latency in Node.js Event Loops
The event loop of a Node.js process is a single thread that polls for incoming connections and executes all application code. When a Node.js request makes a call to an external database, remote service or the filesystem, the event loop automatically directs the application's control flow to some other task, including other connections or callbacks.
CPU-intensive operations block the event loop, preventing it from handling incoming requests or finishing existing requests. A CPU-intensive operation in one business transaction may cause slowness in other business transactions.
Process Snapshots In AppDynamics
A process snapshot describes an instance of a CPU process on an instrumented Node.js node. It generates a process-wide flame graph for a Node.js process over a configurable time range.
Process snapshots provide visibility into the Node.js event loop across all business transactions for the duration of the process snapshot. Process snapshots are useful when the main troubleshooting tools (such as, business transaction snapshots) are inconclusive because the source of latency is a CPU-intensive operation in another business transaction. You can use lists of process snapshots to identify which functions have high CPU times. From the list, you can select and examine process snapshots to identify exactly which functions in your code are blocking the CPU.
For a given Node.js node or tier, you can access the list of process snapshots from the Process Snapshots tab of the node or tier dashboard. You can filter the process snapshot list to display only the snapshots that you are interested in. You can filter by execution time, whether the snapshot is archived, and the GUID of the request. If you access the list from the tier dashboard, you can also filter by node.
For more information on how process snapshots are generated and how to configure them, see Manage Node.js Process Snapshots.
To learn how process snapshots and business transaction snapshots are created, see Process Snapshots and Business Transaction Snapshots.
Process snapshots persist for 14 days, unless you archive them, in which case they are available forever.
A process snapshot contains these tabs:
- Overview
- Flame Graph
- Call Graph
- Allocation Call Graphs
- Hot Spots
Overview
Summarizes the snapshot. Contents vary based on the available information.
Usually contains at least the total execution time, tier and node of the process, timestamp, slowest method and request GUID.
Flame Graph
Provides a visualization of each stack frame’s frequency on the CPU over the duration of a process snapshot. The frame’s position relative to the bottom-most stack depicts the call-stack depth.
The flame graph contains the same information as the call graph, but allows you to quickly spot methods that are consuming more CPU resources relative to others.
The method corresponding to the stack frame on the top edge of the flame graph represents the method’s CPU resource consumption frequency.
To identify long-running CPU executions, look for long horizontal cells on the top edge of the flame graph.
A healthy Node.js process has minimal CPU-blocking activity; correspondingly, a flame graph for a healthy Node.js process has minimal long, horizontal cells along the top edge of its flame graph. See The Flame Graph.
Call Graph
Shows the total execution time and the percentage of the total execution time of each method on the process's call stack. The numbers at the ends of the methods are the line numbers in the source code. You can filter out methods below a certain time to simplify the graph and isolate the trouble spots.
The Time and Percentage columns identify which calls take the longest time to execute.
To see more information about a call, select the call and click Details.
Allocation Call Graph
Available only for process snapshots that are collected manually. See Manage Node.js Process Snapshots.
Shows the amount and percentage of the memory allocated and not freed by each method on the process's call stack during the process snapshot. You can use the Method Size slider to configure how much memory a method must allocate to be displayed in the allocation call graph. You can also filter out methods that consume less than a certain amount of memory to simplify the graph and isolate the trouble spots.
The Size and Percentage columns identify which calls consume the most memory.
The agent cannot report allocations made prior to the beginning of the allocation snapshot.
The allocation reported in the snapshot is the memory that is still referenced when the snapshot ends: memory allocated during the snapshot period minus memory freed during the snapshot period.
For more information about a call, select the call and click Details.
Hot Spots
This tab displays the calls by execution time, with the most expensive calls at the top. To see the invocation trace of a single call in the lower panel, select the call in the upper panel.
Use the Method Time slider in the upper right corner to configure how slow a call must be to be considered a hot spot.