限制 node.js 的内存使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12779724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:26:03  来源:igfitidea点击:

Limiting node.js's memory usage

node.jsmemoryram

提问by Industrial

I am trying to limit a node.jsapplication from using to much memory and I've found out about the --max-stack-size& --max_executable_sizeoptions that are available within V8 to pass when invoking the file, but how should I combine these and possible other arguments to limit max memory usage to 1GB?

我试图限制node.js应用程序使用太多内存,我发现了V8 中可用的--max-stack-size&--max_executable_size选项在调用文件时传递,但是我应该如何结合这些和可能的其他参数来限制最大内存使用1GB?

采纳答案by Josh

https://github.com/joyent/node/wiki/FAQ

https://github.com/joyent/node/wiki/FAQ

What is the memory limit on a node process?

Currently, by default v8 has a memory limit of 512mb on 32-bit systems, and 1gb on 64-bit systems. The limit can be raised by setting --max_old_space_size to a maximum of ~1gb (32-bit) and ~1.7gb (64-bit), but it is recommended that you split your single process into several workers if you are hitting memory limits.

节点进程的内存限制是多少?

目前,默认情况下,v8 在 32 位系统上的内存限制为 512mb,在 64 位系统上为 1gb。可以通过将 --max_old_space_size 设置为最大 ~1gb(32 位)和 ~1.7gb(64 位)来提高限制,但如果您遇到内存限制,建议您将单个进程拆分为多个工作线程.

Value is in megabytes, I believe.

我相信价值以兆字节为单位。

回答by Андрей Сорока

It's now, --max-old-space-sizeno technology limits...

现在,--max-old-space-size没有技术限制......

for example node --max-old-space-size=8192 ./app. We create limit in 8Gb

例如node --max-old-space-size=8192 ./app。我们在8Gb 中创建限制