Does NodeJS respect Docker virtualization and resource limits? Does NodeJS respect Docker virtualization and resource limits? kubernetes kubernetes

Does NodeJS respect Docker virtualization and resource limits?


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

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.

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.

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.