简体   繁体   English

Nodejs虚拟机。 设置内存限制

[英]Nodejs VM. Set memory limit

I'm working now with nodejs virtual machine: 我现在正在使用nodejs虚拟机:

http://nodejs.org/api/vm.html http://nodejs.org/api/vm.html

I'm interesting, is it possible to set memory limit to script and maybe limit to CPU? 我很有趣,是否可以将内存限制设置为脚本,甚至可以将限制设置为CPU?

There is no way to do this at the V8 VM level without affecting the rest of your code that runs in the same process. 在V8 VM级别上无法做到这一点,而又不影响在同一进程中运行的其余代码。 If you are wanting to incorporate these kinds of restrictions, you should be executing the code in a separate process that is properly contained (using the appropriate mechanisms provided by the OS). 如果要合并这些类型的限制,则应在正确包含的单独过程中执行代码(使用操作系统提供的适当机制)。 Linux has cgroups , FreeBSD has jails , and Solaris has zones/containers . Linux有cgroup ,FreeBSD有jail ,Solaris有区域/容器

您可以使用isolated-vm npm并传递memoryLimit选项参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM