When troubleshooting performance issues in ColdFusion, analyzing thread and heap dumps can help diagnose bottlenecks, memory leaks, and deadlocks. The ColdFusion Performance Monitoring Toolset (PMT) is the recommended method for capturing Thread and Heap dumps. It captures them in real-time and allows you to create alerts on system events and trigger the Thread dump and Heap dump automatically (For more details, refer to this article). We will explore alternative ways to capture them if you are not using the PMT. This guide explains how to capture thread and heap dumps for ColdFusion server environments.
What are Thread and Heap Dumps?
- Thread Dump: Captures the state of all running threads, helping identify long-running or blocked threads.
- Heap Dump: Captures memory usage, allowing you to analyze objects consuming memory and detect potential memory leaks.
Capturing Thread Dumps:
Thread dump via ColdFusion:
The best way to capture the thread dump is from ColdFusion programmatically. It would be difficult for the administrator to take point-in-time thread dumps, especially in scenarios where performance degrades over a period and eventually the server stops responding. In such a scenario, it’s appropriate to take the thread dump programmatically using the scheduled task. Below are the steps to create the schedule task and capture the thread dump programmatically.
- Download the takethreaddump.cfm file [here].
- Place the file in the following directory: {ColdFusion-Home}\cfusion\wwwroot\
- Manually trigger the thread dump by running the file via the built-in ColdFusion port. Example: http://127.0.0.1:8500/takethreaddump.cfm
- Locate the thread dump file in the following directory: {ColdFusion-Home}\cfusion\runtime\work\Catalina\localhost\tmp
- Automate thread dumps by creating a scheduled task in the ColdFusion Administrator. Set the task to run at 2-minute intervals (recommended) for continuous monitoring.
Note: Ensure that “Disable access to internal ColdFusion Java components” is unchecked in the ColdFusion Administrator console. Navigate to Server Settings → Settings and verify this option is disabled to allow ColdFusion to create Java objects.
Thread dump via the jstack Command:
If you have the JDK installed on the server, you can make use of the “jstack” command to capture the thread dumps. Navigate to the JDK install path and run the “jstack” command with the PID of the ColdFusion process.
Windows:
\Program Files\Java\jdk-xx\bin> jstack -l (PID of the CF process) > thread_dump.log
Note: The PID of the CF process can be found in the Task Manager in the Windows OS.
Linux:
/usr/lib/jvm/JDK-xx/bin> jstack -l (PID of the CF process) > thread_dump.log
Note: The PID of the CF process can be found using – ps aux | grep coldfusion.
To diagnose performance issues effectively, it is recommended to take multiple thread dumps instead of just one. Ideally, take at least 3 to 5 thread dumps at intervals of 1 to 2 minutes apart. This helps capture patterns over time and more accurately identify running, stuck, or blocked threads.
Capturing Heap Dumps:
To capture the heap dump, use the “jmap” command available in JDK. Run the “jmap” command during the high CPU and Memory usage or performance latency. To diagnose memory-related issues effectively, it is recommended to take at least 1 to 2 heap dumps at different intervals (e.g., before and after a suspected issue or 10 minutes apart). Navigate to the JDK install path and run the “jmap” command with the PID of the ColdFusion process.
jmap -dump:live,format=b,file=heap_dump.hprof <PID>
PID – The PID of the CF process can be found in the Task Manager (Windows OS) or using the “ps aux | grep coldfusion”(Linux).
In case you are seeing the OOM(Out of memory) in the ColdFusion logs, it is crucial to capture a heap dump before the server crashes. You can add the below argument in the jvm.config (located at ColdFusion-Home}\cfusion\bin) to trigger the heap dump during the OOM event.
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath= <please add the path for storing heap dump>
Replace <path_to_store_heap_dump> with the desired location for storing the heap dump.
In addition to the heap dump, it’s helpful to capture the crash event’s timestamp, CPU, and memory usage, and ColdFusion logs to correlate related events.
You must be logged in to post a comment.