Ayende @ Rahien

Refunds available at head office

Optimizations gone wild, O(N!) memory leaks

So, after doing so much work on the indexing optimization, it turned out that we had a bug. I assume that you remember this optimization, right?

image

In which we were able to pre fetch data from the disk and not have to wait for data at all. This all worked beautifully when running on data sets that included simple indexes. But the moment we had map/reduce indexes, something bad happened. That something bad was that we kept missing the batch that we loaded (this relates to how we load & find the appropriate batches).

We do all the lookups by etag, and map/reduce add gaps in the etags. Which meant that we kept missing the etag, and had to start loading things up again. And because whenever we load something we also start loading the next batch…

Here is what the memory looked like:

image

Yup, for every batch we loaded the next 5 batches, for a total of O(N!) items in memory for everything.

Now, we had some cleanup routines, but we did NOT expect to have that much, so we would recover, eventually, but usually not before we consumed all the memory.

Opps!

Tags:

Posted By: Ayende Rahien

Published at

Originally posted at

Comments

Harry McIntyre
12/17/2012 11:27 AM by
Harry McIntyre

Do you have automated tests for catching memory issues, and if so, how do they work?

Ayende Rahien
12/17/2012 11:32 AM by
Ayende Rahien

Harry, No, we don't. We use dog fooding for those sort of issues.

paul
12/17/2012 12:13 PM by
paul

Isn't it a O(n^2) leak?

Joseph Daigle
12/17/2012 12:27 PM by
Joseph Daigle

Yeah, it's (N^2)/2 not N!. You're taking the summation of N...1, not the product.

Ayende Rahien
12/17/2012 12:30 PM by
Ayende Rahien

Paul, No, because each time it will issue a set of additional batches from the start of the next one, and so on. We will miss those, and issue another set, and so on.

Alois Kraus
12/18/2012 08:51 PM by
Alois Kraus

For regression testing you could WMemoryProfiler (https://wmemoryprofiler.codeplex.com/). It is free. You can download the latest sources to get it up and running.

Ayende Rahien
12/18/2012 10:08 PM by
Ayende Rahien

Alois, That is a great project, I am looking forward to digging into that.

Comments have been closed on this topic.