Skip to main content

Include Query Timings

  • When making a query,
    you can request to get detailed stats of the time spent by RavenDB on each part of the query.
    E.g. duration of search, loading documents, transforming results, total duration, etc.

  • By default, the timings stats are Not included in the query results, to avoid the measuring overhead.

  • To include the query timings in the query results:
    add a call to Timings() in your query code, or add include timings() to an RQL query.
    See examples below.

  • In this page:

Include timings in a query

// Define an object that will receive the query timings
QueryTimings timings = null;

var results = session.Query<Product>()
// Use the Customize method to Call Timings, provide an out param for the timings results
.Customize(x => x.Timings(out timings))
// Define query criteria
// i.e. search for docs containing Syrup -or- Lager in their Name field
.Search(x => x.Name, "Syrup Lager")
// Execute the query
.ToList();

// Get total query duration:
// =========================
var totalQueryDuration = timings.DurationInMs;

// Get specific parts duration:
// ============================
IDictionary<string, QueryTimings> timingsDictionary = timings.Timings;
var optimizerDuration = timingsDictionary["Optimizer"].DurationInMs;
var luceneDuration = timingsDictionary["Query"].Timings["Lucene"].DurationInMs;

View timings

  • The detailed timings can be viewed from the Query view in the Studio.

  • Running an RQL query with include timings() will show an additional Timings Tab
    with a graphical representation of the time spent in each query part.

Figure 1. Include timings graphical results

Syntax

IDocumentQueryCustomization Timings(out QueryTimings timings);
ParameterTypeDescription
timingsQueryTimingsAn out param that will be filled with the timings results
QueryTimings
DurationInMslongTotal duration
TimingsIDictionary<string, QueryTimings>Dictionary with QueryTimings info per time part

Timings in a sharded database