将每个进程的Node.js内存使用量限制为小于300MB [英] Limit Node.js memory usage to less than 300MB per process

查看:360
本文介绍了将每个进程的Node.js内存使用量限制为小于300MB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在单独的过程中运行测试,我们的一些测试套件包含20多个文件.我们如何将Node.js进程使用的内存量限制(而不是增加)到少于300MB?如果不限制内存,则我们最多可以使用20x500MB(约10GB),这是太多的内存.

We run tests in separate processes and a few of our test suites contain more than 20 files. How can we limit (instead of increase) the amount of memory a Node.js process uses to less than say 300MB? If we don't limit memory, we could use up to 20x500MB, which is about 10GB, which is too much memory.

我可以在网上找到一些有关增加内存的文章,但是在限制每个进程的内存方面我找不到任何东西.

I can find a few articles online about increasing memory, but I can't find anything on limiting memory per process.

具体来说,我们使用核心child_process模块​​创建子进程,我想我们需要一些标志或arg传递给cp来指定某种内存上限.

Specifically, we are using the core child_process module to create child processes and I guess we need some flag or arg to pass to the cp's to designate a memory cap of sorts.

推荐答案

有用的链接:

nodejs减少了v8垃圾收集器的内存使用量

https://groups.google.com/forum/#!topic /nodejs/IYsQ_bXlzcg

https://www.quora.com/How -does-Node-js-do-内存分配

要考虑的选项:

–nouse-idle-notification

–expose-gc +代码中的gc()函数.

–expose-gc + gc() function from your code.

–max-old-space-size

–max-new-space-size

-最大半空间大小

也为了减少内存,可以使用更少的内存消耗算法,代码可以更友好地使用GC.本地C ++模块也可以提供帮助,但是可以使用valgrind彻底检查它们是否存在内存泄漏和错误.

Also to decrease memory, less memory consuming algorithms can be used, the code can be more GC friendly. Also native C++ modules can help, but check them thoroughly for memory leaks and errors with some valgrind.

也可以将OS中的引号应用于终止超过某些内存限制的进程.

Also quotes from OS can be applied to kill processes which exceed some memory limits.

我知道,没有一些有意义的选项描述,这个答案不是那么有用,但是我现在还不太了解它们,所以这个答案"只是一个方向.

I know, without some concious option descriptions this answer is not so usefull, but I not very good learned them for now, so this "answer" is just a direction.

这篇关于将每个进程的Node.js内存使用量限制为小于300MB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆