Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pm2 shows 1.2GB while heapdump shows 80MB

I'm writing a nodeJS application using node v0.12.7.

I'm running my nodejs application using pm2 v0.14.7.

it appears that i have memory leaks in my application since it bounces from around 180MB when I start it to around 1gb afteer 24 hours.

I'm trying to investigate the issue.

so far i found the following tools:

memwatch-next heapdump node-inspector

with node-inspector i found some cpu issues and i was able to easily fix them.

with memwatch-next and heapdump i'm trying to get a full map of the application memory, the problem is the following:

after 24 hours of my app running and after pm2 show that the memory increases to more then 1gb, when i create a heapdump using any of these tools, it creates a heapdump of about 80MB.

my question is.. where's the rest ?

if the app memory is around 1GB, how can i see the memory map of my entire application in order to find memory leaks? what am I missing ?

any information regarding the issue would be greatly appreciated.

like image 784
ufk Avatar asked Sep 21 '15 11:09

ufk


People also ask

How much memory does pm2 use?

Monitoring With PM2 The default memory consumption is about 50M for the maintenance and 70M for the homepage project. That's all the magic.

What is pm2 heap usage?

The heap is a memory used by programming languages to store global variables. By default, all global variable are stored in heap memory space. It`is maybe because of your programs variable. you can reset it after it exceeded the limit or force pm2 do it for you automatically. pm2 start api.js --max-memory-restart 300M.


1 Answers

Did you use Buffer Object in your code?

A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap

And more,type below code will show

process.memoryUsage();
//ouput { rss: 19730432, heapTotal: 9751808, heapUsed: 4768896 }

confirm if the value of rss key is equal to pm2's display value;

like image 161
plusmancn Avatar answered Sep 17 '22 03:09

plusmancn