Kapitán Mlíko
Kapitán Mlíko

Reputation: 4538

Permanent indexes in RavenDB

I currently want to create some static indexes for RavenDB to gain better performance.

But when I was going through RavenDB documentation there was one specific sentence which really made me reconsider my original intentions.

Therefore, we recommend to base most operations in an application on static indexes, or at least ensure the temporary indexes created by dynamic indexing have been promoted to permanent indexes.

Well since my solution is really large and I don't even know which indexes I need. It would force me to look through whole solution and create static indexes for every other operation. I probably exaggerating, but still... I don't know if all that work will be worth it.

My question is:

How to ensure the temporary indexes have been promoted to permanent indexes?

EDIT:

What I learned is the fact that some indexes gets promoted to permanent/static auto indexes which are persisted and I don't lose them even if I restart Raven server. What I understood is that it depends on Server Configuration options. So some of my indexes have been promoted to permanent and with restart I have lost only those temporary. Nevertheless my question remains.

EDIT2:

I made edits in original question and gathered more information. Take me as really stupid person. I need explanations. Please do not confuse me with things like "permanent/static"

Static index is permanent, but Permanent index is not necessarily static. Maybe I am asking wrong question. I just want to be sure RavenDb server don't have to create new Dynamic index each call of query which I don't really call one hundred times per minute.

RavenDB can analyse a query and create a temporary index on the fly, which will be persisted for some amount of time before then being disposed of.

What I understood from Ravendb server configuration options:

Index gets promoted to Permanent when you use it one hundred times in one minute(default values). And if it remains dynamic and it's not used for 20 minutes it's deleted.(default). But what if I have queries which will be used I don't know TempIndexPromotionMinimumQueryCount / 2 per TempIndexPromotionThreshold. So maybe my question is now:

Is there any significant difference between constantly used but dynamic index and permanent index?

Upvotes: 0

Views: 724

Answers (2)

Dominic Zukiewicz
Dominic Zukiewicz

Reputation: 8444

A dynamic index (constantly used or not):

  1. Is always created by RavenDB because cannot use an existing dynamic/static index to answer your query
  2. Only exists in memory, not on disk.
  3. Will not be there if the Raven Server is restarted
  4. Will be deleted if the usage does not pass a certain threshold of queries/time elapsed
  5. Has a lower priority on resources for maintenance over static indexes

In contrast to static indexes. A static index:

  1. Is either
    • a manually/automatically promoted dynamic index
    • a static index defined manually in Raven Studio
    • Created in .NET code by an application and registered with RavenDB
  2. Is stored on disk
  3. Will be reloaded if Raven Server restarts
  4. Will never be deleted by Raven Server automatically
  5. Is given a higher priority to maintain.

Yes dynamic indexes do have a priority too, but static indexes are first priority in maintenance, followed by dynamic.

You also stated that your application is very 'large' (high volume/high variety/high throughput?), and I assume that there must have been some development cycle on a developer machine. Through developer testing, you may already have indexes created for you. The next steps are how to move them across to production.

You have 3 choices in this:

  1. Let RavenDB work it out itself (dynamic -> static)
  2. Copy/paste the definitions from environment to environment. (static)
  3. [RECOMMENDED] Create the index in code. (static)

A recommended approach, is if you know ahead of time what you are indexing, it is best to create a class that implements AbstractIndexCreationTask<T> and then register it. The documentation for creating a static index in code is found on the RavenDB website. This way you will also have a consistent set of indexes across your environments.

Upvotes: 1

fjxx
fjxx

Reputation: 945

What that statement means is that if a dynamic/temporary index is being used a lot by your application, its better to convert it into a static/permanent index.

Upvotes: 1

Related Questions