Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js 0.12.x memory usage

Tags:

Trying to upgrade my application from node 0.10.x to node 0.12.x family, I was hit with an unpleasant surprise: 0.12 uses about 15%-20% more RAM than 0.10.

Judging by a few threads on io.js issues page, it seems the fault lies with the underlying v8 engine.

Now software update is a difficult proposition to sell to management as it is. Add to that the need to pay for more VPS hardware with few visible benefits, and this becomes a deal breaker for us.

Is there a way to disable whatever new bells & whistles v8 had added that are taking up the additional RAM? Perhaps the touted CPU profiling stuff?

I'm basically looking for a v8 switch that can reduce memory usage to the level comparable to the v8 shipped with node 0.10.

like image 632
panta82 Avatar asked Apr 28 '15 08:04

panta82


People also ask

How much memory does node js use?

By default, Node. js (up to 11. x ) uses a maximum heap size of 700MB and 1400MB on 32-bit and 64-bit platforms, respectively.

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.

Why does Node run out of memory?

A common problem while working on a JavaScript Node. js project is the “JavaScript heap out of memory” error. This error usually occurs when the default memory allocated by your system to Node. js is not enough to run a large project.


1 Answers

You can limit the amount of memory your Node.js process uses with the --max-old-space-size flag. Perhaps you can cap the memory at something acceptable and then benchmark your app to see if it performs acceptably.

node --max-old-space-size=512 myScript.js 

I believe there are also flags that control garbage collection that might be worth exploring. And this GitHub issue about v8 performance profiling etc. may be worth your time reading as well.

like image 154
Trott Avatar answered Sep 27 '22 17:09

Trott