当node脱离v8_nodejs减少了v8垃圾收集器的内存使用量
发布日期:2022-02-18 13:20:07 浏览次数:8 分类:技术文章

本文共 1624 字,大约阅读时间需要 5 分钟。

I'm debugging a nodejs application with util module and while heapUsed value stays around 30-100MB, heapTotal value grows up to 1.4GB.

I've read that this is the way how v8 garbage collector behaves, but the question is how to decrease the amount of memory it allocates (make it less than 1.4GB) if running on 512 MB device for example

解决方案

You need to control the max memory size flags (all sizes are taken in MB).

node --max-executable-size=96 --max-old-space-size=128 --max-semi-space-size=1 app.js

for 32-bit and/or Android and

node --max-executable-size=192 --max-old-space-size=256 --max-semi-space-size=2 app.js

for 64-bit non-android.

These would limit the heap totals to 225mb and 450mb respectively. It doesn't include memory usage outside JS. For instance buffers are allocated as "c memory" , not in the JavaScript heap.

Also you should know that the closer you are to the heap limit the more time is wasted in GC. E.g. if you are at 95% memory usage 90% of the CPU would be used for GC and 10% for running actual code (not real numbers but give the general idea). So you should be as generous as possible with the limits and never exceed say 16% of the maximum memory usage (I.E. heapUsed/limit should not be greater than 0.16). 16% is just something I recall from some paper, it might not be the most optimal.

Flags:

--max-executable-size the maximum size of heap reserved for executable code (the native code result of just-in-time compiled JavaScript).

--max-old-space-size the maximum size of heap reserved for long term objects

--max-semi-space-size the maximum size of heap reserved for short term objects

转载地址:https://blog.csdn.net/weixin_28929351/article/details/111980988 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:sqlserver获得年月_SQLServer提取日期中的年月日季
下一篇:epplus 清除第二行以后的数据_zookeeper原理篇Zookeeper的数据存储与恢复原理

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年04月10日 04时41分36秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章