I have some Node.JS processes taking more memory than I think they require. I suspect this is due to lazy GC.
In my case, I have several Node.JS processes running, across 3 user accounts. (root
and two others)
After searching, it seems that I can limit the amount of 'unused' space that is held in memory by simply using the --max_old_space_size=X
option. Where X
is the number of megabytes allowed.
However, this does not seem to be documented so I am a little concerned that I should not be using it. Can this be documented, or is it deprecated?
I believe it is not documented because we have tried to stay away from documenting V8 options.
Oh, I see it now. node --help
shows an options called --v8-options
. That is where it is documented. One might be able to make that more clear, but I'm not even sure that would help, so I'll just close the issue. Thanks.
That's a lot of documentation that would then fall on our shoulders to keep up to date. The V8 project should manage their own documentation IMO. It also looks like that v8-flags repo hasn't been updated in over 2 years.
@cjihrig Oh, no, I mean to duplicate just the link. But if the list is outdated. then may be this is not a good idea. Sorry.
Ah, sorry, I misunderstood what you meant by "duplicate it." I wouldn't have a strong opinion on duplicating the link if the v8-flags repo was being kept up to date.
+1 on at least mentioning something about max_old_space_size in the docs. If only to link to somewhere else.
I agree that it's not Nodes' job to document V8 options, but still believe this memory option is a special case that deserve mentioning in the docs.
Which would be best to use:
#!/usr/local/bin/node --max_old_space_size=4096
..
or
const v8 = require('v8');
v8.setFlagsFromString('--max_old_space_size=4096');
..
Edit:
After 1 hour of searching I'm still have no idea what's the default node value, and that using this v8 option will (officially) guarantee more memory allocated.
@fractalf A posteriori, Node.js sets memory limit near 1.5 GB by default (at least for x64 OS).
@fractalf FWIW the definitions of default values are in v8/src/heap/heap.cc: https://github.com/nodejs/node/blob/ec02b811a8a5c999bab4de312be2d732b7d9d50b/deps/v8/src/heap/heap.cc#L82 (max_old_space_size
is actually used to configure max_old_generation_size
when its value is larger than 0). So on 64-bit machines that(the old generation alone) would be 1400 MB.
@vsemozhetbyt @joyeecheung Thanks!
"scripts": {
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js"
}
instead of:
"scripts": {
"dev": "node --max-old-space-size=4096 node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --progress --config build/webpack.dev.conf.js"
},
使用这个npm包,可以帮助到你. 在使用vue-cli@3时触发。
Most helpful comment
@fractalf FWIW the definitions of default values are in v8/src/heap/heap.cc: https://github.com/nodejs/node/blob/ec02b811a8a5c999bab4de312be2d732b7d9d50b/deps/v8/src/heap/heap.cc#L82 (
max_old_space_size
is actually used to configuremax_old_generation_size
when its value is larger than 0). So on 64-bit machines that(the old generation alone) would be 1400 MB.