Set Index Priority Operation
-
In RavenDB, each index has its own dedicated thread for all indexing work.
By default, RavenDB prioritizes processing requests over indexing,
so indexing threads start with a lower priority than request-processing threads. -
Use
SetIndexesPriorityOperation
to increase or lower the index thread priority. -
Indexes scope:
Index priority can be set for both static and auto indexes. -
Nodes scope:
The priority will be updated on all nodes in the database group. -
Setting the priority can also be done from the indexes list view in the Studio.
-
In this page:
Index priority
Setting the priority will affect the indexing thread priority at the operating system level:
Priority value | Indexing thread priority at OS level | |
---|---|---|
Low | Lowest | <ul><li>Having the Lowest priority at the OS level, indexes will run only when there's a capacity for them, when the system is not occupied with higher-priority tasks.</li><li>Requests to the database will complete faster.Use when querying the server is more important to you than indexing.</li></ul> |
Normal (default) | Below normal | <ul><li>Requests to the database are still preferred over the indexing process.</li><li>The indexing thread priority at the OS level is Below normal while Requests processes have a Normal priority.</li></ul> |
High | Normal | <ul><li>Requests and Indexing will have the same priority at the OS level.</li></ul> |
Set priority - single index
- Sync
- Async
// Define the set priority operation
// Pass index name & priority
var setPriorityOp = new SetIndexesPriorityOperation("Orders/Totals", IndexPriority.High);
// Execute the operation by passing it to Maintenance.Send
// An exception will be thrown if index does not exist
store.Maintenance.Send(setPriorityOp);
// Define the set priority operation
// Pass index name & priority
var setPriorityOp = new SetIndexesPriorityOperation("Orders/Totals", IndexPriority.High);
// Execute the operation by passing it to Maintenance.SendAsync
// An exception will be thrown if index does not exist
await store.Maintenance.SendAsync(setPriorityOp);
Set priority - multiple indexes
- Sync
- Async
// Define the index list and the new priority:
var parameters = new SetIndexesPriorityOperation.Parameters
{
IndexNames = new[] {"Orders/Totals", "Orders/ByCompany"},
Priority = IndexPriority.Low
};
// Define the set priority operation, pass the parameters
var setPriorityOp = new SetIndexesPriorityOperation(parameters);
// Execute the operation by passing it to Maintenance.Send
// An exception will be thrown if any of the specified indexes do not exist
store.Maintenance.Send(setPriorityOp);
// Define the index list and the new priority:
var parameters = new SetIndexesPriorityOperation.Parameters
{
IndexNames = new[] {"Orders/Totals", "Orders/ByCompany"},
Priority = IndexPriority.Low
};
// Define the set priority operation, pass the parameters
var setPriorityOp = new SetIndexesPriorityOperation(parameters);
// Execute the operation by passing it to Maintenance.SendAsync
// An exception will be thrown if any of the specified indexes do not exist
await store.Maintenance.SendAsync(setPriorityOp);
Syntax
// Available overloads:
public SetIndexesPriorityOperation(string indexName, IndexPriority priority);
public SetIndexesPriorityOperation(Parameters parameters);
Parameters | ||
---|---|---|
indexName | string | Index name for which to change priority |
priority | IndexingPriority | Priority to set |
parameters | SetIndexesPriorityOperation.Parameters | List of indexes + Priority to set. An exception is thrown if any of the specified indexes do not exist. |
public enum IndexPriority
{
Low,
Normal,
High
}
public class Parameters
{
public string[] IndexNames { get; set; }
public IndexPriority Priority { get; set; }
}