How to detect leak in non-heap memory in Node JS? - node.js

Our NodeJS application is facing memory leak issues for a while. Unlike other heap memory leak issues, I found there is a leak in non-heap using NewRelic APM tool. I'm using node 14.15.5 version.
I had gone through various articles to detect memory leaks in heap section but couldn't find one for non-heap. Due to this, GC metrics are poor which in turn increases avg. latency of the application. How do I find the non-heap memory leak? Does NodeJS upgrade helps?

Related

NodeJs - RSS and external memory increases significantly, heap memory increases slowly. What can be the causes?

In my NodeJS application:
1.Is it correct that RSS and external memory increases significantly, but heap memory increases slowly?
Is it correct that the external memory increases more than the heapTotal?
I tried using the chrome inspect, but as soon as i launch the snapshots the application crashes.
Also, i don't think analyzing the heap memory i find the problem.
see the graph here
Any suggestions?

How do I determine the current Nodejs max heap size and increase it

I have an Angular application build that is failing with Javascript heap allocation errors. How do I determine what the configured heap size is for a Nodejs process.
Then how do I increase it.
I've Googled this for an hour and just see a variety of contradictory and outdated answers and nothing definitive.
Win 10
Node 10.16.3
Use process.memoryUsage() to get the heap size
To increase (Basically set)
node test.js --max-old-space-size=8192

Is there a way to debug memory leaks which happen outside v8 heap

I have a production application running on NodeJS which serves a decent amount of traffic. While things are smooth post deployment, the performance starts to degrade after few hours.
We noticed on newrelic that the non-heap memory of NodeJS continues to increase steadily while V8 heap is kind of consistent. We have tried using Chrome DevTools but couldn't find the issue. Are there any tools which will help me debug the memory leak happening outside V8 heap?
Image: https://i.imgur.com/SP9pAQt.png
Tried Google Chrome DevTools to find the leak but no luck.

Optimize Node.js memory consumption

I'm writing a simple cms in Node.js, Express and MongoDB. I'm planning to run a different Node.js process for every site. The problem is that after startup the process takes about 90m of RAM and for me it's too big (eight site take all server RAM). This memory is taken after the first connection to the site and other connections don't affect the memory.
Is there a guideline or a list of "best practices" to optimize this memory usage? I'm trying to track where the memory is allocated with process.memoryUsage() or a similar function but it's not simple to do this.
Is not a problem of memory leaks or something similar because the memory usage doesn't grow up after the first connection, so probably the optimization could be in loading less modules or do something differently...
The links below may help you to understand and detect memory leaks (if they do exist):
Debugging memory leaks in node.js
Detecting Memory Leaks in Node.js Applications
Tracking Down Memory Leaks in Node.js
These SO questions may also be useful:
How to monitor the memory usage of Node.js?
Node.js Memory Leak Hunting
Here is a quick fix, a node.js lib that will restart the any node process once it reaches a certain size.
https://github.com/DoryZi/memory_limiter
Set the --max_old_space_size CLI flag to control the maximum heap size. There's a post that describes Running a node.js app in a low-memory environment
tl;dr; Try setting this value, in megabytes, to about 80% of the maximum memory footprint you want node to try to remain under. e.g. to run app.js and keep it under 500MB RAM used
node --max_old_space_size=400 app.js
This setting is also described in the Node JS CLI documentation

Memory leak in Node.js outside of heap?

I've just fixed a memory leak in my node application which was in the heap of node.
I've profiled that with Google's Profiler and managed to fix the memory leak.
Now my app is running again for some time, and I've seen that the heap size is pretty constant. No memory leak anymore. But when I check my server's free RAM, I see a decrease...
When I restart my node server the RAM is up to it's normal free RAM.
Now I've heard about that Node.js can save objects and stuff outside of the heap. I think that is what's causing the memory leak here.
How can I see what's taking up the memory? Can't really profile anything, or can I?
I'm using:
node.js: v0.8.18 and
socket.io: v0.9.13
Some other node modules that I'm using are: nodetime, heapdump (will delete this, though), jquery, crypto, request and querystring.
Some graphs:
Free OS memory and
Node RSS and Heap used

Resources