Identify memory leaks with nodejs-dashboard

Will Button
InstructorWill Button
Share this video with your friends

Social Share Links

Send Tweet
Published 8 years ago
Updated 5 years ago

In this lesson, I introduce a memory leak into our node.js application and show you how to identify it using the Formidable nodejs-dashboard. Once identified, we will add garbage collection stats to the error console allowing us to correlate garbage collection with the increased memory usage.

[00:00] The last thing I want to show you is what you can do with the memory usage screen in NodeJS-dashboard. I have my express application here, and I've got the root endpoint set up so it generates a random number of fake lorem words, somewhere between one and a thousand words.

[00:19] Then it splits it into an array. For each word in the array, it pushes it up to a global variable or a global array and stores it there. Returning to the NodeJS-Dashboard, whenever I kick off a bunch of users to hit this endpoint, if you watch the resident memory down there, you can see that it's continually increasing.

[00:44] One of the things I can do to troubleshoot this further is to install an NPM module called the Garbage Collection Profiler. Again, I'll save this to a devDependency, because it's not something you're going to want to do in production.

[00:58] While that's installing, I can return to my application code. I'll create a profiler object that's going to require the Garbage Collection Profiler. That creates an event stream so I can do profiler.on and listen for the garbage collection event. Then I'm just going to write out to the error console whenever this gets called the info object that gets created.

[01:26] Now, returning to the NodeJS-dashboard, whenever I start hitting this with users. As the memory starts to increase, we'll see the garbage collections operations happening in the error console.

[01:39] By watching this run, what I'm seeing is the garbage collections operations are happening, but my heap usage is not going down, indicating that something's not being released from memory, giving me the opportunity to troubleshoot that further.

[01:53] The next step I would take in troubleshooting this would be to start taking heap dumps at the beginning of the application life cycle. Later, whenever we're up around this point when we've got a bunch of memory allocated, take that heap dump and compare it before and after to see what it is that's consuming the memory.

Oliver Mensah
Oliver Mensah
~ 6 years ago

Please how do I start the nodejs dashboard and use it with any node application

Igor Berquo Canedo
Igor Berquo Canedo
~ 5 years ago

https://egghead.io/lessons/node-js-install-nodejs-dashboard

Markdown supported.
Become a member to join the discussionEnroll Today