简体   繁体   English

如何设置通过内存使用包运行的Nodejs传递最大旧空间大小的内存限制

[英]How to set pass max-old-space-size memory limit to Nodejs running with memory-usage package

I am using https://www.npmjs.com/package/memory-usage to see how my Node application uses the memory, by running 'memory-usage app.js' in MACOS terminal. 我正在使用https://www.npmjs.com/package/memory-usage通过在MACOS终端中运行“ memory-usage app.js”来查看我的Node应用程序如何使用内存。 However, after some testing, it always crash at 1.4GB. 但是,经过一些测试,它总是在1.4GB时崩溃。

In normal nodejs command, to set the memory limit higher, I could just use 'node --max-old-space-size=8192 app.js'. 在普通的nodejs命令中,要设置更高的内存限制,我可以只使用'node --max-old-space-size = 8192 app.js'。 However running 'memory-usage --max-old-space-size=8192 app.js' won't work. 但是运行'memory-usage --max-old-space-size = 8192 app.js'将不起作用。

My Mac has following RAM details: 我的Mac有以下RAM详细信息:

BANK 0/DIMM0: 存储区0 / DIMM0:

Size: 4 GB Type: DDR3 Speed: 1867 MHz 大小:4 GB类型:DDR3速度:1867 MHz

BANK 1/DIMM0: BANK 1 / DIMM0:

Size: 4 GB Type: DDR3 Speed: 1867 MHz 大小:4 GB类型:DDR3速度:1867 MHz

What is the maximum size I can go for my Nodejs application and how to set that with memory-usage? 我可以为Nodejs应用程序使用的最大大小是多少,以及如何通过内存使用量设置该大小?

Thank you. 谢谢。

Try setting it via NODE_OPTIONS : 尝试通过NODE_OPTIONS设置:

Unix: Unix:

export NODE_OPTIONS="--max_old_space_size=8192" && memory-usage app.js

Windows: 视窗:

set NODE_OPTIONS="--max_old_space_size=8192" && memory-usage app.js

Its likely that the memory-usage executable is just ignoring your max-old-space argument. 内存使用可执行文件可能只是忽略了max-old-space参数。 You should be able to find a way around that in their docs. 您应该能够在他们的文档中找到解决该问题的方法。 It looks like Node has default memory allocation of 1G on 64bit systems. 看起来Node在64位系统上的默认内存分配为1G。

See related (possibly duplicate) thread. 请参阅相关(可能重复)的线程。 Limiting node.js's memory usage 限制node.js的内存使用量

1.4G sounds a bit high to me. 1.4G对我来说有点高。 I wonder if you're leaking memory somewhere? 我想知道您是否正在某处泄漏内存?

See also: How to monitor the memory usage of Node.js? 另请参阅: 如何监视Node.js的内存使用情况?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM