Skip to main content

Lucene queries monitor

Info

The Lucene queries monitor shows what a node of Mercury DB (HgDB) 3.0 is searching right now and how its queries behaved in the past: the queries that are running at the moment, the latest slow and finished queries, and the statistics of the queries (number of executions, times, errors). The monitor looks at one node: the one that answered the request.

What you can see​

  • Active queries: the kind of the query, the user, the thread, the time elapsed so far and the full text of the query. When the query is executed by another node of the cluster, the entry has the state waiting for node with the name of that node.
  • Statistics: queries with the same fingerprint (the text of the query with the constants replaced with ?) are counted together: number of executions, errors, average time, approximate percentiles (p50, p95), the longest time, the sum of times and the sum of hits. A histogram of the times and the charts of active queries and of queries per second are drawn from the same data.
  • Latest slow queries: the queries that lasted at least as long as the threshold (by default 1 second). A slow query has a plan button: the plan of the query after the execution, with the decision of the optimizer (root first or child first, and why) and the time and hits of every step. See Calibrating the Lucene query optimizer.
  • Latest finished queries: the history with the time, the number of hits and the error, if the query failed.
Remember
  • The state is kept in the memory of the node and disappears after its restart. In a cluster, check each node separately.
  • The full text of the queries is visible, so the page and the services are available only for users with the role mrc-sysadmin.

Administration page​

Lucene queries monitor

The Show plan link of a slow query opens its plan:

Plan of a slow query

What the plan contains

The plan always shows the query, the cost estimated by the optimizer and the actual time and number of hits of every step (for example ACTUAL: 21 ms, hits=88229). The decision of the optimizer about the order of execution (root first or child first, and why) appears only when the query has a condition on a child case (a subquery). A query without a subquery, like the one in the screenshot, has a short plan with a single step.

The page is available in the application under the address <address of the application>/static/admin/lucene-queries.html (a link is on the home page of the application, next to the logging levels and the data secretaries). It is available only for a user with the role mrc-sysadmin after logging in with the form. The page refreshes itself (every 2 seconds by default) and lets you clear the statistics and the history. A click on a row of the statistics shows the distribution of the times of that query.

The button Save sample for calibration downloads a file with the real queries of the node (from the lists of the latest slow and finished queries) in the format read by the command -lc of mercury-cmd (one query per line: name<TAB>query, lines with # are comments). The option only queries with a subquery (on by default) keeps queries with a condition on a child case, which are the ones the optimizer chooses a plan for. The file contains no user names, but it contains real values from the queries (names, addresses), so it is personal data: treat it accordingly. The page asks for confirmation before the download.

REST services​

The same data are available through the REST service LuceneQueriesExtRest (described in the OpenAPI specification of the application). It requires the scope (role) mrc-sysadmin in the OAuth token or a logged-in session of such a user.

OperationAddressPurpose
getQueriesStatePOST <address of the application>/rest/service/LuceneQueriesExtRest/getQueriesStateactive queries, latest slow and finished queries, statistics (parameter limit: 100 by default, 1000 at most)
resetQueriesStatisticsPOST <address of the application>/rest/service/LuceneQueriesExtRest/resetQueriesStatisticsclears the statistics and the history (active queries stay)

Configuration​

All parameters are optional (file mercury.properties).

ParameterDefaultMeaning
mercury.lucene.query.monitor.enabledtrueswitches the monitor on or off
mercury.lucene.query.monitor.slowMillis1000threshold of a slow query in milliseconds
mercury.lucene.query.monitor.historySize200size of each of the two histories (slow and latest queries)
mercury.lucene.query.monitor.maxQueryChars10000the text of a query longer than this number of characters is shortened
mercury.lucene.query.monitor.maxFingerprints500the largest number of separate statistics; the rest are counted together in one row
mercury.lucene.query.monitor.planMaxChars20000the longest plan text kept for a slow query (longer is cut); 0 switches the plans off

The plan text is built only after a query turns out to be slow, so fast queries do not pay for it. The plans and the sample are available in the administration page only (not in the REST service LuceneQueriesExtRest). The cost of registering a query is small: a measurement in a unit test gave about 14 microseconds per query, including the creation of the fingerprint.