Over a million developers have joined DZone.

Optimizing Performance of RavenDB's Indexing Process

· Database Zone

Build fast, scale big with MongoDB Atlas, a hosted service for the leading NoSQL database. Try it now! Brought to you in partnership with MongoDB.

The actual process done by RavenDB to index documents is a fairly complex one. In order to understand what exactly happened, I decided to break it apart to pseudo code.

It looks something like this:

<span class="kwrd">while</span> database_is_running:
  stale = find_stale_indexes()
  lastIndexedEtag = find_last_indexed_etag(stale)
  docs_to_index = get_documents_since(lastIndexedEtag, batch_size)
  
  filtered_docs = execute_read_filters(docs_to_index)
  
  indexing_work = []
  
  <span class="kwrd">for</span> index <span class="kwrd">in</span> stale:
    
    index_docs = select_matching_docs(index, filtered_docs)
    
    <span class="kwrd">if</span> index_docs.empty:
      set_indexed(index, lastIndexedEtag)
    <span class="kwrd">else</span>
      indexing_work.add(index, index_docs)
      
  <span class="kwrd">for</span> work <span class="kwrd">in</span> indexing_work:
  
     work.index(work.index_docs)

And now let me show you the areas in which we did some perf work:

All of which gives us a major boost in the system performance. I’ll discuss each part of that work in detail, don’t worry 

Now it's easier than ever to get started with MongoDB, the database that allows startups and enterprises alike to rapidly build planet-scale apps. Introducing MongoDB Atlas, the official hosted service for the database on AWS. Try it now! Brought to you in partnership with MongoDB.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

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

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

{{ parent.tldr }}

{{ parent.urlSource.name }}