我如何确定正确的“最大旧空间大小"?对于 node.js? [英] How do I determine the correct "max-old-space-size" for node.js?
问题描述
我在理解 Node.js 如何根据参数 max-old-space-size
进行操作时遇到了一些麻烦.
例如,就我而言,我正在运行两个 t2.small
AWS 实例(2GB 内存).
不知道为什么,但我确实设置了 max-old-space-size=4096
(4GB).节点在这种情况下做什么?这种配置会导致可能的内存分配失败吗?
如何根据服务器资源确定max-old-space-size
的正确值?
我的应用程序的内存使用量不断增加,我正在尝试了解节点内部的所有内容.
旧空间"是 V8 托管(也称为垃圾收集)堆(即 JavaScript 对象所在的位置)中最大且最可配置的部分,并且 --max-old-space-size
标志控制其最大大小.随着内存消耗接近极限,V8 会在垃圾回收上花费更多时间以释放未使用的内存.
如果堆内存消耗(即 GC 无法释放的活动对象)超过限制,V8 将使您的进程崩溃(由于缺乏替代方案),因此您不想将其设置得太低.当然,如果您将其设置得太高,那么 V8 允许的额外堆使用可能会导致您的整个系统内存不足(并且由于缺乏替代方案而交换或终止随机进程).
总而言之,在具有 2GB 内存的机器上,我可能会将 --max-old-space-size
设置为大约 1.5GB,以便为其他用途留出一些内存并避免交换.>
I'm having some trouble to understand how Node.js acts based on the parameter max-old-space-size
.
In my case, for example, I'm running two t2.small
AWS instances (2GB of RAM).
Not sure why, but I did set max-old-space-size=4096
(4GB). What does node do in this case? Could this configuration lead to a possible memory allocation failure?
How do I determine the correct value of max-old-space-size
based on the server resources?
My application is constantly growing the memory usage and I'm trying to understand everything about node internals.
"Old space" is the biggest and most configurable section of V8's managed (aka garbage-collected) heap (i.e. where the JavaScript objects live), and the --max-old-space-size
flag controls its maximum size. As memory consumption approaches the limit, V8 will spend more time on garbage collection in an effort to free unused memory.
If heap memory consumption (i.e. live objects that the GC cannot free) exceeds the limit, V8 will crash your process (for lack of alternative), so you don't want to set it too low. Of course, if you set it too high, then the additional heap usage that V8 will allow might cause your overall system to run out of memory (and either swap or kill random processes, for lack of alternative).
In summary, on a machine with 2GB of memory I would probably set --max-old-space-size
to about 1.5GB to leave some memory for other uses and avoid swapping.
这篇关于我如何确定正确的“最大旧空间大小"?对于 node.js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!