Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit usage of virtual memory by node.js?

I am working in an embedded environment, where resources are quite limited. We are trying to use node.js, which works well, but typically consumes about 60 megabytes of virtual memory (real memory used is about 5 megabytes.) Given our constraints, this is too much virtual memory; we can only afford to allow node.js to use about 30 megabytes of VM, at most.

There are several command-line options for node.js, such as "--max_old_space_size", "--max_executable_size", and "--max_new_space_size", but after experimentation, I find that these all control real memory usage, not maximum virtual memory size.

If it matters, I am working in a ubuntu linux variant on an ARM architecture.

Is there any option or setting that will allow one to set the maximum amount of virtual memory that a node.js process is allowed to use?

like image 753
Mike Avatar asked May 25 '12 23:05

Mike


People also ask

How do I limit Nodejs memory usage?

The limit can be raised by setting --max_old_space_size to a maximum of ~1024 (~1 GB) (32-bit) and ~1741 (~1.7 GiB) (64-bit), but it is recommended that you split your single process into several workers if you are hitting memory limits."

What is Node js default memory limit?

Tuning the Garbage Collector In Node < 12 , it sets a limit of 1.5 GB for long-lived objects by default. If this exceeds the memory available to your dyno, Node could allow your application to start paging memory to disk.

How do I check Nodejs memory usage?

memoryUsage() method is an inbuilt method of the process module that provides information about the current processes or runtime of a Node. js program. The memory usage method returns an object describing the memory usage in bytes of the Node.

What is RSS memory Nodejs?

rss , or resident set size, refers to the amount of space occupied in the main memory for the process, which includes code segment, heap, and stack.


1 Answers

You can use softlimit to execute the node with limited size. Or you can directly use setrlimit of Linux, but not really sure how to call it from NodeJS, see this SO question

like image 70
Mustafa Avatar answered Oct 07 '22 15:10

Mustafa