-
Notifications
You must be signed in to change notification settings - Fork 44
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
Potential memory leak #75
Comments
Hmm, I'm not sure, here are some thoughts/questions I have:
In general, almost all of the memory allocations involving lmdb-store are during writes, not reads. Serializations require buffer allocations, and LMDB has to allocate pages, and none of that is needed during reads. |
No, it is a default
Nope, not using it yet. Just regular dbs and a couple of
I don't think so. I tried it with
That's my main suspect too. What would be the good way to track the number of open cursors / read transactions?
It actually gets killed by the OS OOM killer, I'll try to set I will likely get back to this by the end of the week, will try to come up with some repro. I was hoping the fact that the drop of the P.S. Not sure, maybe we actually see this issue here: nodejs/node#38300 (Edit: probably not as I am testing with Node 14.17.3 that should contain a fix for this issue) |
For read txns, you can check with There is no public API for the number of cursors, although you could set a breakpoint in lmdb-store/index.js to look at the Our lmdb-store server/app certainly tests cursor usage heavily, when we run reindexing operations, we make millions of getRange()/cursor traversal calls, and I think we typically don't see any more than 100MB of external buffer memory usage (whereas our server process will easily consume 40GB of RSS for the shared memory maps, but none of that is dirty, and the OS doesn't complain at all, merrily reclaiming any memory needed for other processes). However, we rarely have any overlapping cursor traversals (there are almost all basically directly converted to arrays), and for any long lived cursor traversals, I use |
I couldn't repro this with Also, NodeJS has several similar issues, some of them linked at the bottom of this thread: nodejs/node#31641 (for anyone experiencing similar symptoms) |
For anyone reading - don't take this is advice - I'm not fully aware of consequences Continuing this, in my search for answer to this question I stumbled on nodejs/help#1518 (comment) where trying different allocator was suggested. On a test run I did try This suggest to me that there is no measurable leak here and the problem is that default allocator just "perform worse" for the type of work we are doing (?). |
I am investigating a memory leak in one project and suspect that it might be caused by
lmdb-store
somehow.The leak is not happening in v8 - it occurs somewhere in native C++ code (I see big RSS values with normal Total V8 Heap values).
Also, I realize that when dealing with LMDB we should check for "dirty" pages only. I do not rely on RSS readings alone - using
pmap -x
to monitor the actual "dirty" memory of the Node process.So, I am sampling memory in Node and see the following results:
Up to a point
heapTotal + external
matches pretty closelydirty
value returned bypmap
. But then at some point, I see this:So essentially Node releases 750MB of buffers but
dirty
value frompmap
doesn't change. RSS doesn't change as well. Eventually the process OOMs.My best guess is that those allocated buffers are somehow retained in
lmdb-store
but I may be completely missing something. I didn't investigate memory leaks in native code before, so not sure what would be the next step to confirm or discard this hypothesis.Do you think it is possible?
P.S. some context: the code causing those allocations does long-living cursor iterations (may traverse 100,000+ items) with corresponding
gets
. Also, this mostly happens in a sync manner (sadly parts of the code are in the user-land and we don't have control over it).The text was updated successfully, but these errors were encountered: