Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get the max heap size of a node.js application

Now I am using node.js in paas platform. And the container has memory limit. Now I want to get the maximum of the heap size of node.js application. I know that use the parameter "--max-old-space-size", I can set the max heap size, but I want to know how to get the default value of "--max-old-space-size". For example, if the container's memory is 512m , so the maximum of node.js heap size can not be greater than it. How can I get the value?

like image 727
qibobo Avatar asked Oct 29 '15 15:10

qibobo


People also ask

What is my maximum heap size?

The default maximum Java heap size is 256 MB.

How do I check my current Node memory limit?

Currently, by default V8 has a memory limit of 512mb on 32-bit systems, and 1gb on 64-bit systems. The limit can be raised by setting --max-old-space-size to a maximum of ~1gb (32-bit) and ~1.7gb (64-bit), but it is recommended that you split your single process into several workers if you are hitting memory limits.


2 Answers

You can try the v8 module, it is documented here: https://nodejs.org/api/v8.html

I believe getHeapStatistics() function will give you everything you need

like image 161
Alex Michailidis Avatar answered Oct 01 '22 10:10

Alex Michailidis


you can use the process.memoryUsage https://nodejs.org/api/process.html#process_process_memoryusage

like image 35
tony_k Avatar answered Oct 01 '22 10:10

tony_k