Home Does NodeJS respect Docker virtualization and resource limits?

# Does NodeJS respect Docker virtualization and resource limits?

Kir
1#
Kir Published in 2017-12-07 21:52:36Z
 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. 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. 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?
Matt
2#
 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.