Optimizations gone wild, O(N!) memory leaks
Join the DZone community and get the full member experience.Join For Free
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?
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:
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.
Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.