[Node] Memory bloat in node.js app

Hi there
Old user of newrelic, first time using it in a nodejs app.
I added the agent and since then, the app shows increased memory use.
I read the support article here but at least some of its content seems to be outdated. Also, I’m not sure how I should determine the cause for the memory leak. We do use mongodb but I don’t think we use cursors (at least, not intentionally).

What do I do?

Hello @shai.yallin :wave:

Thanks for joining the community!

I have a few more questions for you:

First, are you seeing a memory leak or general increased memory usage?

If memory is steady or fluctuating up and down, but is higher than without the Node agent installed, next we will need to know how much memory increases with the Node agent running compared to without, and how close your application is to your memory and CPU thresholds. Some increased memory usage is expected, the Node agent adds objects to the work done by your application to track transaction, report timing, etc. but our goal is to keep the agent footprint as minimal as possible!

For a memory leak, we’ll expect to see memory usage that continually increases until the instance is restarted, often you will see and increase in response time too. You can use the NodeVM page and set the time window to 7 days to see the long term trends. The NodeVM page reports metrics from the same process the Node agent is running on, so if you don’t see evidence of a memory leak on the NodeVM page then the Node agent is not involved.

If the NodeVM page is showing signs of a memory leak, we will need to get more information to find the source of the leak. While this is not affiliated with New Relic, Chrome DevTools has a great guide on fixing memory problems and how to record Heap Snapshots:

It is best to get a heap snapshot after the application has fully started up and during normal traffic. From here, we will look for if the source is the Node agent, or if the agent is making an existing leak worse. The Node agent annotates resources with context such as database connections, request objects, promises, etc. to report performance data, meaning even a small leaking promise, with the New Relic data leaking as well can add up to a large leak over time.

Some more information that would be good to know:

Regarding MongoDB cursors, if you don’t think you are using cursors, you likely are not! Although to double check, you can search your code for cursor methods.

Let us know any questions! Once we know more about what kind of memory bloat you are seeing, we can determine next steps!

P.S. Thank you for the feedback on the ’ Troubleshooting large memory usage’ document! I’m going to bring this to the attention of our product team, it can certainly use an update!

1 Like