As I understand it is possible to set a maximum memory usage limit for an application like this:
node --max_old_space_size=500 app.js
Is it possible to get a value of the max_old_space_size
from the code?
UPDATE
With the help of @Grégory NEUT we found out that v8.getHeapStatistics()
contains a field heap_size_limit
which looks like what I am looking for.
However I'm still not sure about it since I didn't find any official documentation (or some piece of code from Node.js) which will approve this theory.
I also don't understand why heap_size_limit
becomes 557842432
bytes (557.8
MB) when I set max_old_space_size
to 500
MB
--max_old_space_size=... limits the total size of all objects on the heap.
By default, the memory limit in Node. js is 512 MB. To increase this amount, you need to set the memory limit argument —-max-old-space-size . It will help avoid a memory limit issue.
The NODE_OPTIONS --max-old-space-size environment variable allows to increase Node's max heap size. Setting an environmental variable allows Node to read this value from your environment and so we don't need to pass this value as an argument every time we run Node command.
This tool will append --max-old-space-size=4096 in all node calls inside your node_modules/.
In the Node.js v9.4.0 Documentation you can find the function v8.getHeapStatistics() that gives you the heap size information.
UPDATE 2019: Node.js v11.x Documentation
LEQADA Example from the comment:
For max_old_space_size=500
heap_size_limit : 557842432
total_available_size : 548898944
For max_old_space_size=900
heap_size_limit : 977272832
total_available_size : 968329344
EDIT : process.memoryUsage() do not give informations about the max size of the heap
In the Node.js v9.4.0 Documentation you can find the function process.memoryUsage() that gives you the heap size information.
UPDATE 2019: Node.js v11.x Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With