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 toTimings()
in your query code, or addinclude 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;
// Define an object that will receive the query timings
QueryTimings timings = null;
var results = await asyncSession.Query<Product>()
// Use the Customize method to Call Timings, provide an out param for the timings results
.Customize(x => x.Timings(out timings))
// Define the search criteria
// Search for docs containing Syrup -or- Lager in their Name field
.Search(x => x.Name, "Syrup Lager")
// Execute the query
.ToListAsync();
// 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;
var results = session.Advanced.DocumentQuery<Product>()
// Call Timings, provide an out param for the timings results
.Timings(out QueryTimings 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;
var results = await asyncSession.Advanced.AsyncDocumentQuery<Product>()
// Call Timings, provide an out param for the timings results
.Timings(out QueryTimings timings)
// Define the search criteria
// Search for docs containing Syrup -or- Lager in their Name field
.Search(x => x.Name, "Syrup Lager")
// Execute the query
.ToListAsync();
// 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;
from "Products"
where search(Name, "Syrup") or search(Name, "Lager")
include timings()
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.
Include timings results
Syntax
IDocumentQueryCustomization Timings(out QueryTimings timings);
Parameter | Type | Description |
---|---|---|
timings | QueryTimings |
An out param that will be filled with the timings results |
QueryTimings |
||
---|---|---|
DurationInMs | long |
Total duration |
Timings | IDictionary<string, QueryTimings> |
Dictionary with QueryTimings info per time part |