简体   繁体   English

如何限制节点进程的 CPU 和内存使用

[英]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 initgrunt 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.

相关问题 如何通过node.js限制虚拟内存的使用? - How to limit usage of virtual memory by node.js? 如何限制 Docker 构建命令的 CPU 使用率? - How to limit CPU usage of Docker build command? 如何限制节点应用内存大小,以及如何验证当前内存使用情况和容量? - How to limit node application memory size, and how to verify current memory usage and capacity? 如何限制节点侧(而不是操作系统侧)的node.js中的内存使用? - How can I limit memory usage in node.js on the node-side (not OS side)? 监视Node.js进程以获取每个进程的最大内存使用率 - Monitoring Node.js processes for max memory usage per process 增加所有 Node.js 进程的内存限制 - Increase memory limit to all Node.js processes 如何使用节点读取 aws cpu 使用情况? - how to read aws cpu usage using node? 由于多个 node.js 进程,React-scripts 100% CPU 使用率 - React-scripts 100% CPU usage due to multiple node.js processes 如何通过NodeJS获取Tomcat本地服务器的内存和CPU使用率 - How to Get Memory & CPU usage of Tomcat local server via NodeJS 如何在Mac上使用Prometheus监视nodejs cpu和内存使用情况? - How to use Prometheus to monitor nodejs cpu and memory usage on Mac?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM