[英]How to limit CPU and memory usage for node processes
I would like to install a Ghost Blog on a shared server via GitHub .我想通过 GitHub 在共享服务器上安装一个 Ghost 博客。 During the installation, I need to run
npm install, grunt init
and grunt prod
.在安装过程中,我需要运行
npm install, grunt init
和grunt prod
。 My host provides 500 MB memory usage, if a process uses more than 600 MB he kills it.我的主机提供 500 MB 内存使用量,如果一个进程使用超过 600 MB,他会杀死它。
Therefore I need an option to limit the memory usage of these processes because they all need more than 500 MB of memory!因此我需要一个选项来限制这些进程的内存使用,因为它们都需要超过 500 MB 的内存!
I tried to run the processes with --max-old-space-size=450
but it does not seem to work.我尝试使用
--max-old-space-size=450
运行进程,但它似乎不起作用。
I would be glad if anyone could provide me a link to a tutorial or documentation about running node processes with options.如果有人可以为我提供有关使用选项运行节点进程的教程或文档的链接,我会很高兴。
Thank you!谢谢!
UPDATE: Since I've posted this the installation of Ghost has changed completely.更新:自从我发布这篇文章以来,Ghost 的安装已经完全改变了。
From node v8+, typing the following:从节点 v8+,键入以下内容:
node --help
show a --v8-options option.显示 --v8-options 选项。 Then typing:
然后输入:
node --v8-options
gives:给出:
...
--max_old_space_size (max size of the old space (in Mbytes))
type: int default: 0
--initial_old_space_size (initial old space size (in Mbytes))
type: int default: 0
...
I have managed to use the first option like this:我设法使用了这样的第一个选项:
node --max-old-space-size=250 `which npm` install
Here we told node to limit RAM usage to 250Mo, the 'which npm' part gives the current npm path and 'install' is the script you want to run.在这里,我们告诉 node 将 RAM 使用限制为 250Mo,'which npm' 部分提供当前的 npm 路径,'install' 是您要运行的脚本。
This is how you do it.这就是你如何做到的。
You send a command to limit the ram usage.您发送一个命令来限制 ram 的使用。
npm install --max-old-space-size=400
我使用以下内容,它就像一个魅力
NODE_OPTIONS=--max_old_space_size=50 npm install
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.