Answer the question
In order to leave comments, you need to log in
NodeJS: heapTotal consumption is growing. Memory leak?
I'm testing the service with ab, I get the following memory consumption graph:
Where:
Green graph - heapUsed.
Black - heapTotal.
Blue - RSS.
According to heapUsed, it is clear that the memory is growing and clearing. Everything seems to be ok. But heapTotal and RSS are constantly growing.
If you stop all requests for the service, then the graph will look like this:
heapUsed will fall, but heapTotal and RSS will not.
Is this behavior a sign of a memory leak? Why isn't heapTotal cleared?
Answer the question
In order to leave comments, you need to log in
Is not.
heapTotal is the total memory allocated by V8. This memory is generally freed only on exit. Memory allocation is slow, so V8 does not return it, assuming it might be needed again. If the garbage collector is under heavy load, V8 tries to increase the memory in order to run it less often.
A leak is when the GC (garbage collector) cannot remove the used object because someone is referencing it, which leads to an increase in memory.
Judging by your charts, the black and blue bands are always growing, but it is not known how much time has passed. Run and test for about five minutes, and then look, and show us the result.
Yesterday, there was only an article that a leak was found in iojs, but has not yet been fixed.
But I understand you nodejs?
There are many options for why a leak occurs. Perhaps there is a jamb in the code, when elements are not removed from some data structure, but only added, perhaps there is a jamb somewhere in NodeJS itself. Try to localize the problem more specifically, i.e. it is necessary to look what data structure constantly increases in volume. And then you can either change your code, or tell the NodeJS authors about the bug.
Or you can just restart NodeJS at a certain interval.
Another option may help How to avoid a memory leak in nodejs?
I do not know the intricacies of memory management (but I know that there are many nuances that depend on the system). But I watched the rss change statistically in one project. RSS only grows for a while (in my case, several days) and then stabilizes at a certain level (in my case, for several months). It remains to wait for stabilization and then it will be seen that there are no memory leaks.
Put the test at night.
Launch:
HeapTotal and RSS are on the rise. HeapUsed ranges from 65MB to 350MB
In the
morning:
HeadTotal and RSS growth stopped and are 1.46-1.49GB and 1.50-1.53GB
HeapUsed ranges from 1.345GB where to 1.456 GB
The test stopped. On the one hand, everything is OK, but for some reason the lower limit of the HeapUsed interval has grown greatly from 65MB to 1.345GB .
I'll put a test of the day for 3 on a separate server and see the result.
Thanks everyone for the replies!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question