6

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?

Mike
  • 69
  • 1
  • 2
  • Why should that be a problem? Linux uses over-allocation: This virtual memory will only exist as entries inside the process page table until it is *acutually* used. – Turbo J May 27 '12 at 02:20
  • Hm. I'm not sure. This is an embedded environment (meaning: no disk space) so wouldn't all virtual allocations use up some real memory? I will pose that thought to my boss, but I have the feeling that it won't make any difference; I've been ordered to reduce the footprint and arguing that I shouldn't have to is not going to carry much weight. The 'customer is always right' sort of thing. Besides, I've run into another issue; I wrote a function using setrlimit() to limit the virtual memory usage to less than 55 megs, and now node.js exits with a malloc error. Any suggestions? – Mike May 29 '12 at 02:15
  • Hi Mike. How did you solve this? – Industrial Oct 08 '12 at 10:43

1 Answers1

1

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

Community
  • 1
  • 1
Mustafa
  • 10,013
  • 10
  • 70
  • 116
  • Thanks. I did find setrlimit(), used it to write a plugin for node.js, and it does work - but now I get an error message from node.js that malloc() is failing because it can't allocate as much memory (55 megs) as it wants. A very ungraceful way of handling a lack of memory, it would seem. So now I'm trying to figure out if I can rebuild node.js and leave out something to reduce the memory footprint. Any ideas? – Mike May 29 '12 at 02:22