NodeJS是否遵守Docker虚拟化和资源限制? [英] Does NodeJS respect Docker virtualization and resource limits?

查看:116
本文介绍了NodeJS是否遵守Docker虚拟化和资源限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,某些应用程序不了解Linux内核隔离和虚拟化功能,例如cgroups.其中包括topfreeps之类的系统实用程序,还包括Java之类的平台.

It is known that some applications aren't aware of Linux kernel isolation and virtualization features such as cgroups. This includes system utils like top, free and ps, but also platforms like Java.

我最近阅读了一篇文章,这表明在Kubernetes中运行JVM时,您应该对Java堆大小实施手动限制,以免发生错误.

I've recently read an article which suggests that when running JVMs in Kubernetes, you should enforce manual limits on the Java heap size to avoid errors.

我在任何地方都找不到NodeJS是否也适用.在Kubernetes的NodeJS应用程序上是否需要实现上述类似设置?--max_old_space_size=XXX?

I cannot find anywhere whether this is also true for NodeJS. Do I need to implement something like above to set --max_old_space_size=XXX on my NodeJS application in Kubernetes?

推荐答案

NodeJS进程将尝试分配内存,而不管容器的限制如何,就像Java一样.

A NodeJS process will try an allocate memory regardless of the container limits, just like Java.

在进程上设置限制将有助于阻止OS终止进程,特别是在受限环境中,即使Node可能在限制范围内运行,Node也会尝试分配超出内存限制的内存.

Setting a limit on the process will help stop the OS from killing the process, particularly in constrained environments where Node might try allocate past the memory limit even though Node could probably run inside the limit.

如果您正在运行一个接近使用内存限制的应用程序,那么添加内存限制设置只会更改故障情况. NodeJS和JVM将有机会因内存不足错误(OOM)而退出,而不是被操作系统杀死.当进程接近内存限制时,此过程可能会缓慢进行爬网,并且垃圾回收器会尽最大努力将进程保持在限制之下.

If you are running an app that is close to using the memory limit then adding the memory limit settings just changes the failure scenario. NodeJS and the JVM will have a chance to exit with an out of memory error (OOM) rather than be killed by the operating system. The process will likely slow to a crawl as it nears the memory limit and the garbage collector tries the best it can to keep the process below the limit.

请注意,旧空间只是NodeJS中多个内存空间之一.只能限制新空间(半空间)和旧空间.

Note that the old space is only one of multiple memory spaces in NodeJS. Only the new space (semi spaces) and old space can be limited.

--max_semi_space_size (max size of a semi-space (in MBytes), the new space consists of two semi-spaces)
    type: int  default: 0
--max_old_space_size (max size of the old space (in Mbytes))
    type: int  default: 0

其他堆空间通常很小,并且足够静态,不必担心.

The other heap spaces are generally small and static enough not to worry about.

运行本机代码的模块可以在堆外部分配内存,并且不受选项限制.

Modules that run native code can allocate memory outside the heap and can't be limited by an option.

这篇关于NodeJS是否遵守Docker虚拟化和资源限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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