{{ !articles[0].partner.isSponsoringArticle ? "Platinum" : "Portal" }} Partner
architects,nosql,tips and tricks

Debugging Memory Issues with RavenDB using WinDBG

We had gotten a database export that showed a pretty rough case for RavenDB. A small set of documents (around 7K) that fan out in multiple map/reduce indexes to be around 70K to 180K (depending of which index is used).

As you can imagine, this puts quite a load on the system, I tried to use the usual methods (dotTrace, hand picking, etc) and we did get some good results on that, we found some pretty problematic issues along the way, and it was good. But we still had the RavenDB process take way too much memory. That means that we had to pull the big guns, WinDBG.

I took a dump of the process when it was using about 1 GB of memory, then I loaded that dump into WinDBG (6.2.9200.20512 AMD64).

I loaded SOS:

.loadby sos clr

Then, the first thing to do was to try to see what is going on with the threads:


As you can see, we have a small number of threads, but nothing to write home about. The next step is to see if we have anything very big in the heap:

!dumpheap –stat


The first number is the method table address, the second is the count, and the third is the total size. The problem is that all of that combine doesn’t reach near as much memory as we take.

I guess it is possible that we hold a lot of data in the stack, especially since the problem is likely caused by indexing.

I decided to map all of the threads and see what they are doing.


Switches me to thread #1, and we can see that we are currently in a waiting. Dumping the stack reveals:


This seems to be the debugger thread. Let us look at the rest:

  • 2 – Finalizer
  • 3 – Seems to be an inactive thread pool thread.
  • 6 – appears to be an esent thread:
    I am not sure what this is doing, and I am going to ignore this for now.
  • 7 – also esent thread:

And… I got tired of this, and decided that I wanted to do something more productive, which is to selectively disable things in RavenDB until I find something that drops the memory usage enough to be worth while.

Whack a mole might not be a great debugging tool, but it the essence of binary search. Or so I tell myself to make my conscience sleep more easily. 

For reference, you can look at the dump file here.

Published at DZone with permission of {{ articles[0].authors[0].realName }}, DZone MVB. (source)

Opinions expressed by DZone contributors are their own.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks