Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a thread dump of a running Node.js process?

In the Java JVM, kill -3 forces the process to print the current stack traces of all running threads. I found it very effective to quickly locate bottlenecks.

Is there an equivalent in V8? Can I make V8 print the current stack trace?


Clarification: I assume, due to the asynchronous nature of node, it will be less useful than for a typical non-asynchronous program. Still, if there is an easy way to get access to a few stack traces, it does not take much time to look at it.

From my experience, some obvious bottlenecks can be quickly located that way before you need to switch to more advanced tools.

like image 402
Philipp Claßen Avatar asked Nov 14 '17 10:11

Philipp Claßen


People also ask

How do you pull a thread dump?

Ctrl + Break (Windows) In Windows operating systems, we can capture a thread dump using the CTRL and Break key combination. To take a thread dump, navigate to the console used to launch the Java application, and press the CTRL and Break keys together.

Can you get thread dump from heap dump?

yes, loaded hprof using VisualVM and it has option to show thread dumps.

Where is thread dump stored?

file-path: is the file path where thread dump will be written in to. As per the example thread dump of the process would be generated in /opt/tmp/threadDump.

Is thread dump and heap dump same?

A thread dump is a dump of the stacks of all live threads. Thus useful for analysing what an app is up to at some point in time, and if done at intervals handy in diagnosing some kinds of 'execution' problems (e.g. thread deadlock). A heap dump is a dump of the state of the Java heap memory.


1 Answers

You can accomplish the same using heapdump tool. I found the below article of the same which is below (It also works for me):

https://medium.com/better-programming/make-a-dump-of-the-v8-heap-and-inspect-for-your-node-app-b69f7b68c162

like image 134
Viral Patel Avatar answered Sep 22 '22 04:09

Viral Patel