Hey, I am facing a issue regarding high memory usage by a container which is running next-js web application. I assigned 4gb RAM to the container by now when i checked the host usage it is showing high memory usage and upon debug I found that container is exceeding the memory limits. What is the way to restrict?
Have you tried limits.memory.enforce
and/or limits.memory.swap
?
What will these commands will do and How can I reset everything to be normal?
Right now there’s a cash and slab showing high numbers.
Ideally, you would want to first figure out why that process requires so much memory. There might be some configuration that reduces the needs to memory.
You can find information on these two configuration keys at Instance options - Incus documentation
limits.memory.swap
controls whether the instance can use the system swap to swap out memory to the disk. The default is to make do with the available memory. In your case it may not help a lot because it appears that the whole running service has to be in memory while executing. The default value is 10
, which means not to use the swap at all. If you decrease, the likeliness of using the swap will increase.
limits.memory.enforce
controls whether the limit is hard (cannot exceed the limit) or soft (may exceed).
Note that if an instance has a service that requires more memory but does not have it, it will get in a situation of swapping to disk, increasing CPU use and not getting the work done.
To try out the configuration, use as follows:
incus config get mycontainer limits.memory.enforce
incus config set mycontainer limits.memory.enforce hard
incus config get mycontainer limits.memory.swap
incus config set mycontainer limits.memory.swap 5