-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory Leak in V8 CpuProfiler #23070
Comments
@nodejs/v8 |
I think this is most likely going to be fixed by #21558. |
Yep, if the issue is not present in 10.11.0 then #21558 should fix it - it essentially backports all the CPU profiler changes that happened between V8 in Node 8 & 10. We did a lot of work on memory consumption of the CPU profiler so overall consumption should be much lower as well as fixing this leak 👍 |
I can't reproduce the leak I see in 8.12.0 with 10.11.0. I still see some increase in memory consumption for 10.11.0 but by far less then with 8.12.0. I have to take a closer look first to find the cause - it could be something completely unrelated. I tried also Node 10.9.0 today and expected behavior like in 8.12.0, but actually 10.9.0 doesn't seem to leak. The Node 10 backport PR has only 4 commits whereas that one for node 8 has 17 so maybe it has been fixed in Node 10 already before. |
Seems this is not correct. Stopping the profiler actually releases the memory but only if all profiling sessions are stopped. Usually we first start the next session before stopping the current one to avoid the overhead of shutting down and starting up profiler. |
Yep those fixes were in V8 already so they didn't need to be backported. The CPU profiler will increase memory usage in general - we need to copy a bunch of data out of the heap so that it can be used off-thread to process the samples. We reduced the additional memory overhead caused by the CPU profiler by about 75% recently - that's what we are backporting to Node 8 and what you hopefully already see in Node 10. |
ok thanks. Should the extra memory consumption in CpuProfiler saturate at some point? In my current sample I see an increase of a few MBytes/hour. |
I think the CPU profiler memory usage should be somewhat proportional to V8 heap size. We store metadata for each function/code object, so if the V8 heap is still growing then this metadata will grow too. Can you still see that increase with 10.11.0? |
Yes, I still see an increase with 10.11.0 but significant lower then with 8.12.0. I just started a test session with heap profiler attached to get more insight. Unfortunately my testsetup has several other dependencies so it will take a while to get concrete data. |
I let my app running for a few hours using 10.11.0 and memory consumption increased continuously. For some reason the rate increased after around 3.5h from around 10MByte/hour to ~20 MByte/h. In sum there are ~150MByte inside Callstack:
I did also a test to use the Problematic sequence:
Working sequence:
The disadvantage of the working sequence is that we found that Is the overlapping approach correct/allowed/supported? |
@nodejs/diagnostics fyi as CpuProfiler is intended to be a Tier 1 diagnostics tool |
Is the overlapping approach correct/allowed/supported? I'm trying to reproduce the leak with a small repro. Are you able to cut down the amount of actual server code you are running and still reproduce the issue? Any help you can give with a smaller/shareable repro would be really useful. One other thing - are you calling |
I was out the last day; will try today to get a reproducer I can share. I tried already with a small sample but failed. Seems the amount of code in use matters. |
@psmarshall I created a private repo with a stripped down version of the sample I used and added you as collaborator. Please let me know if this is a working setup for your. Thanks! |
Thanks, I'll take a look. |
I've logged an upstream bug on the V8 tracker: https://bugs.chromium.org/p/v8/issues/detail?id=8253. The root cause is explained there. As a workaround, deleting all profiles before starting a new profile will fix the leak - i.e. in the repro code, call |
@psmarshall Thanks a lot! Could some collaborator please update the labels as it turned out that this is not just effecting v8.x. I updated already the top message. |
Thanks for the repro 👍 , it really helped me track it down. Yep, this affects v10.x and master. I'll land the fix on V8 master and then hopefully backport it to v8.x and 10.x. |
I used the It seems quite a lot allocations happen during @psmarshall Based on your comments above that some data from heap needs to be copied I'm not sure if this is expected - in special that RSS stays high. This happens with 8.12.0 and 10.11.0 but the amount of memory allocated if by far higher for 8.12.0 (I assume because of fixes already in 10.x and pending in 8.x). Call Stack:
Edit: the "sticky" RSS seems to happen only in Linux, on Windows it goes down. So I assume this is caused by different implementations of the heap on these two OSes. |
@Flarna Interesting. Are you able to put together a basic repro the shows the behaviour? Then I'll log a v8 bug and look into it. I'll be travelling for the next week so probably after that. |
Hmm, I was sure that I posted a reproducer last week but it seems something got wrong. I'm currently on sick leave with no access to it so it will take a bit. |
I was able to create a small reproducer which shows this high RSS peak during CpuProfiler start and sticky RSS in Linux. Run the following with
Results for It can be seen that the shrink of V8 Heap results also on RSS shrink for windows and linux but the RSS high peak is sticky on linux. I assume this is because V8 heap allocates/releases full pages wheres that other allocations are done via To me it looks like |
@Flarna Thanks I will take a look |
Upstream v8 issue: https://bugs.chromium.org/p/v8/issues/detail?id=8364 |
Some update here from chromium tracker:
Edit: Update with backport to NodeJs v8. |
Thanks for reminding me, here is the backport for Node 8: #25041 |
It seems there is a memory leak in V8 CPU Profiler. If have seen that RSS steadily increases but V8 heap stays constant. I did a fast heap profiling with MSVC and got following stack frames which seem to point to the leak:
Stopping profiling doesn't release the memory.
I did also a fast test with NodeJS 10.11.0 and it seems the issue is not present there.
I will continue my investigations but any hint which fix in V8 would be needed to be backported to get this fixed is welcome.
The text was updated successfully, but these errors were encountered: