Over a million developers have joined DZone.

Debugging Memory Issues with RavenDB using WinDBG

DZone's Guide to

Debugging Memory Issues with RavenDB using WinDBG

· Database Zone
Free Resource

Learn how to move from MongoDB to Couchbase Server for consistent high performance in distributed environments at any scale.

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.

Want to deliver a whole new level of customer experience? Learn how to make your move from MongoDB to Couchbase Server.


Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


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

{{ parent.tldr }}

{{ parent.urlSource.name }}